Django: Iterating over a set of queries without a cache

I have a dumb simple loop

for alias in models.Alias.objects.all() :
    alias.update_points()

but, looking at QuerySet django, it seems to support _result_cacheall previous results. These are the Gigs and Gigs of my car, and ultimately everything explodes.

How can I throw away everything that I will never need?

+5
source share
2 answers

Use the queryset method iterator()to return models to pieces without populating the result cache:

for alias in models.Alias.objects.iterator() :
    alias.update_points()
+11
source

You should save the changes to the database.

for alias in models.Alias.objects.all() :
    alias.update_points()
    alias.save()
0
source

All Articles