1
0
mirror of https://github.com/django/django.git synced 2025-02-28 03:24:39 +00:00

Fixed #23623 -- Reduced memory consumption when generating ModelChoiceField choices

This commit is contained in:
Thomas Chaumeny 2014-10-09 13:02:25 +02:00 committed by Tim Graham
parent 115c307184
commit fa534b92dd

View File

@ -1083,12 +1083,12 @@ class ModelChoiceIterator(object):
if self.field.cache_choices: if self.field.cache_choices:
if self.field.choice_cache is None: if self.field.choice_cache is None:
self.field.choice_cache = [ self.field.choice_cache = [
self.choice(obj) for obj in self.queryset.all() self.choice(obj) for obj in self.queryset.iterator()
] ]
for choice in self.field.choice_cache: for choice in self.field.choice_cache:
yield choice yield choice
else: else:
for obj in self.queryset.all(): for obj in self.queryset.iterator():
yield self.choice(obj) yield self.choice(obj)
def __len__(self): def __len__(self):