summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
authorEtienne Chové <chove@crans.org>2019-10-11 13:00:06 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-11 13:28:06 +0200
commita12f9cd95a24573612daaf844ec97d4aed12446d (patch)
treebbafd294e9623ea8252481c245c68d1abd0c3467 /tests/model_forms
parent7d1bf29977bb368d7c28e7c6eb146db3b3009ae7 (diff)
downloaddjango-a12f9cd95a24573612daaf844ec97d4aed12446d.tar.gz
Added ModelChoiceField test for validation with to_field_name.
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/test_modelchoicefield.py4
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(''))