mirror of https://github.com/django/django.git
[3.0.x] Added ModelChoiceField test for validation with to_field_name.
Backport of a12f9cd95a
from master
This commit is contained in:
parent
cf7ef5d258
commit
82ba905db3
|
@ -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(''))
|
||||
|
|
Loading…
Reference in New Issue