diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2014-11-12 21:18:11 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2014-11-12 22:38:18 +0100 |
| commit | bfb11b95626f39e2f5e18d97d7761c6f93dcc1a9 (patch) | |
| tree | cd6c1a8b009ef7153c128b53583b415a2575623b /tests | |
| parent | 11b7680d0e640a7d4b1c942f74e9197b6ec924b1 (diff) | |
Fixed #23795 -- Fixed a regression in custom form fields
Custom form fields having a `queryset` attribute but no
`limit_choices_to` could no longer be used in ModelForms.
Refs #2445.
Thanks to artscoop for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_forms/tests.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 98de9c95f2..86a027e4d4 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -2377,6 +2377,17 @@ class StumpJokeForm(forms.ModelForm): fields = '__all__' +class CustomFieldWithQuerysetButNoLimitChoicesTo(forms.Field): + queryset = 42 + + +class StumpJokeWithCustomFieldForm(forms.ModelForm): + custom = CustomFieldWithQuerysetButNoLimitChoicesTo() + class Meta: + model = StumpJoke + fields = () # We don't need any fields from the model + + class LimitChoicesToTest(TestCase): """ Tests the functionality of ``limit_choices_to``. @@ -2407,6 +2418,14 @@ class LimitChoicesToTest(TestCase): self.assertIn(self.threepwood, stumpjokeform.fields['has_fooled_today'].queryset) self.assertNotIn(self.marley, stumpjokeform.fields['has_fooled_today'].queryset) + def test_custom_field_with_queryset_but_no_limit_choices_to(self): + """ + Regression test for #23795: Make sure a custom field with a `queryset` + attribute but no `limit_choices_to` still works. + """ + f = StumpJokeWithCustomFieldForm() + self.assertEqual(f.fields['custom'].queryset, 42) + class FormFieldCallbackTests(TestCase): |
