Skip to content

Instantly share code, notes, and snippets.

@rrei
Created July 29, 2020 14:26
Show Gist options
  • Save rrei/d42728d666bbcab37fd989d14e43ea8a to your computer and use it in GitHub Desktop.
Save rrei/d42728d666bbcab37fd989d14e43ea8a to your computer and use it in GitHub Desktop.
Basic formulation of the problem
def do_stuff(obj):
"""Performs some simple processing on `obj`."""
obj.y = obj.related_obj.x ** 2 + 1 # DB query to fetch `.related_obj`
obj.save() # DB query to update `obj`
# Obtain a large queryset for this example.
qs = MyFurstModel.objects.all()
# Simply iterate over the queryset and do some processing on each element.
# Sounds simple enough, right? WRONG!
for obj in qs:
do_stuff(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment