Added ModelChoiceField test for validation with to_field_name.
This commit is contained in:
parent
7d1bf29977
commit
a12f9cd95a
|
@ -55,6 +55,10 @@ class ModelChoiceFieldTests(TestCase):
|
||||||
with self.assertRaisesMessage(ValidationError, msg):
|
with self.assertRaisesMessage(ValidationError, msg):
|
||||||
f.clean(c4.id)
|
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):
|
def test_choices(self):
|
||||||
f = forms.ModelChoiceField(Category.objects.filter(pk=self.c1.id), required=False)
|
f = forms.ModelChoiceField(Category.objects.filter(pk=self.c1.id), required=False)
|
||||||
self.assertIsNone(f.clean(''))
|
self.assertIsNone(f.clean(''))
|
||||||
|
|
Loading…
Reference in New Issue