From a12f9cd95a24573612daaf844ec97d4aed12446d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Etienne=20Chov=C3=A9?= Date: Fri, 11 Oct 2019 13:00:06 +0200 Subject: [PATCH] Added ModelChoiceField test for validation with to_field_name. --- tests/model_forms/test_modelchoicefield.py | 4 ++++ 1 file changed, 4 insertions(+) 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(''))