diff -r eec2c68ffa03 django/forms/models.py
a
|
b
|
|
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) |
diff -r eec2c68ffa03 tests/regressiontests/model_forms_regress/tests.py
a
|
b
|
|
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) |