diff --git a/django/forms/models.py b/django/forms/models.py
index 61ff8e4..40bc942 100644
|
a
|
b
|
class ModelChoiceIterator(object):
|
| 910 | 910 | for obj in self.queryset.all(): |
| 911 | 911 | yield self.choice(obj) |
| 912 | 912 | |
| | 913 | def __len__(self): |
| | 914 | return len(self.queryset) |
| | 915 | |
| 913 | 916 | def choice(self, obj): |
| 914 | 917 | if self.field.to_field_name: |
| 915 | 918 | key = obj.serializable_value(self.field.to_field_name) |
| 916 | 919 | else: |
| 917 | 920 | key = obj.pk |
| 918 | 921 | return (key, self.field.label_from_instance(obj)) |
| | 922 | |
| 919 | 923 | |
| 920 | 924 | |
| 921 | 925 | class ModelChoiceField(ChoiceField): |
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index 85e284b..4c23b81 100644
|
a
|
b
|
class CustomFieldSaveTests(TestCase):
|
| 100 | 100 | # It's enough that the form saves without error -- the custom save routine will |
| 101 | 101 | # generate an AssertionError if it is called more than once during save. |
| 102 | 102 | form = CFFForm(data = {'f': None}) |
| 103 | | form.save() |
| 104 | | No newline at end of file |
| | 103 | form.save() |
| | 104 | |
| | 105 | |
| | 106 | class ModelChoiceIteratorTests(TestCase): |
| | 107 | def test_len(self): |
| | 108 | class Form(forms.ModelForm): |
| | 109 | class Meta: |
| | 110 | model = Article |
| | 111 | fields = ["publications"] |
| | 112 | |
| | 113 | Publication.objects.create(title="Pravda", |
| | 114 | date_published=date(1991, 8, 22)) |
| | 115 | f = Form() |
| | 116 | self.assertEqual(len(f.fields["publications"].choices), 1) |