Interesting, is there a way to peek for an existing record instead of calling get to see whether the record exists in the database? I'm thinking of making this snippet of code a bit more efficient
try: obj = Hackathon.objects.get(**each_dict) except Hackathon.DoesNotExist: obj = Hackathon(**each_dict) obj.save() On Saturday, September 18, 2021 at 10:31:46 AM UTC-4 J.T. wrote: > Take a look at update_or_create() > > > https://docs.djangoproject.com/en/3.2/ref/models/querysets/#update-or-create > > On Sat, Sep 18, 2021, 9:27 AM Adib Neymar Jr. <[email protected]> wrote: > >> Hello, >> >> What is a good way to compare new data with old data which is updated >> everyday with Django ORM? Basically I have a scraper which fetches >> hackathons everyday (basically just a celery task) and I want the newest to >> be unioned it with my master database which has the latest fetched >> hackathons from yesterday. I don't want to destroy my master database and >> then just upload everything that I just fetched since that seems wasteful. >> This is my strategy in approaching my problem but I am open to hear other >> options as well. >> >> >> Thanks, >> >> >> >> Adib >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAN%3Doy7JkqHEtaizgKtHniofSS7T%2BybqVer0mJc1uRPRLupUSdQ%40mail.gmail.com >> >> <https://groups.google.com/d/msgid/django-users/CAN%3Doy7JkqHEtaizgKtHniofSS7T%2BybqVer0mJc1uRPRLupUSdQ%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/07e19d5a-579a-4ec6-91f0-4ccba9790d0fn%40googlegroups.com.

