summaryrefslogtreecommitdiff
path: root/django/forms/models.py
diff options
context:
space:
mode:
authorMarti Raudsepp <marti@voicecom.ee>2015-11-05 19:02:18 +0200
committerTim Graham <timograham@gmail.com>2015-11-09 12:47:08 -0500
commit3144785ebf9fdc19639ef3d35267283f5c2f321a (patch)
tree7939b9faf0d1b46e110a28d9016bdba3122cbd99 /django/forms/models.py
parenta42c5376e764712d8ff4a1f9dd3c2d5537722288 (diff)
[1.8.x] Fixed #25683 -- Allowed ModelChoiceField(queryset=...) to accept Managers.
This fixes a regression from refs #25496. Backport of 1155843a41af589a856efe8e671a796866430049 from master
Diffstat (limited to 'django/forms/models.py')
-rw-r--r--django/forms/models.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/forms/models.py b/django/forms/models.py
index 1036e9b288..384dddf242 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -1092,17 +1092,19 @@ class ModelChoiceIterator(object):
def __iter__(self):
if self.field.empty_label is not None:
yield ("", self.field.empty_label)
- method = 'all' if self.queryset._prefetch_related_lookups else 'iterator'
- queryset = getattr(self.queryset, method)
+ queryset = self.queryset.all()
+ # Can't use iterator() when queryset uses prefetch_related()
+ if not queryset._prefetch_related_lookups:
+ queryset = queryset.iterator()
if self.field.cache_choices:
if self.field.choice_cache is None:
self.field.choice_cache = [
- self.choice(obj) for obj in queryset()
+ self.choice(obj) for obj in queryset
]
for choice in self.field.choice_cache:
yield choice
else:
- for obj in queryset():
+ for obj in queryset:
yield self.choice(obj)
def __len__(self):