diff options
| author | Etienne Chové <chove@crans.org> | 2019-10-11 13:00:06 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-11 13:28:06 +0200 |
| commit | a12f9cd95a24573612daaf844ec97d4aed12446d (patch) | |
| tree | bbafd294e9623ea8252481c245c68d1abd0c3467 | |
| parent | 7d1bf29977bb368d7c28e7c6eb146db3b3009ae7 (diff) | |
Added ModelChoiceField test for validation with to_field_name.
| -rw-r--r-- | tests/model_forms/test_modelchoicefield.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py index adb3754382..74ef14aa73 100644 --- a/tests/model_forms/test_modelchoicefield.py +++ b/tests/model_forms/test_modelchoicefield.py @@ -55,6 +55,10 @@ class ModelChoiceFieldTests(TestCase): with self.assertRaisesMessage(ValidationError, msg): f.clean(c4.id) + def test_clean_to_field_name(self): + f = forms.ModelChoiceField(Category.objects.all(), to_field_name='slug') + self.assertEqual(f.clean(self.c1.slug), self.c1) + def test_choices(self): f = forms.ModelChoiceField(Category.objects.filter(pk=self.c1.id), required=False) self.assertIsNone(f.clean('')) |
