Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #18829 -- Fixed ModelChoiceIterator length

Thanks facundo.olano at gmail.com for the report and thikonom for
the initial patch.
  • Loading branch information...
commit 1c11ee63459c4362affbd6a20f2ddf9c2ecd8dce 1 parent 150e202
@vanschelven vanschelven authored claudep committed
View
3  django/forms/models.py
@@ -917,7 +917,8 @@ def __iter__(self):
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))
View
1  tests/modeltests/model_forms/tests.py
@@ -989,6 +989,7 @@ def test_with_data(self):
(c2.pk, "It's a test"),
(c3.pk, 'Third'),
(c4.pk, 'Fourth')])
+ self.assertEqual(5, len(f.choices))
with self.assertRaises(ValidationError):
f.clean('')
with self.assertRaises(ValidationError):
Please sign in to comment.
Something went wrong with that request. Please try again.