1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #18829 -- Fixed ModelChoiceIterator length

Thanks facundo.olano at gmail.com for the report and thikonom for
the initial patch.
This commit is contained in:
Klaas van Schelven
2013-02-23 20:11:47 +01:00
committed by Claude Paroz
parent 150e202172
commit 1c11ee6345
2 changed files with 3 additions and 1 deletions

View File

@@ -917,7 +917,8 @@ class ModelChoiceIterator(object):
yield self.choice(obj)
def __len__(self):
return len(self.queryset)
return len(self.queryset) +\
(1 if self.field.empty_label is not None else 0)
def choice(self, obj):
return (self.field.prepare_value(obj), self.field.label_from_instance(obj))