mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #24295 -- Allowed ModelForm meta to specify form field classes.
Thanks Carl Meyer and Markus Holtermann for the reviews.
This commit is contained in:
parent
e8cf4f8abe
commit
00a889167f
6 changed files with 92 additions and 26 deletions
|
@ -1431,3 +1431,21 @@ class TestModelFormsetOverridesTroughFormMeta(TestCase):
|
|||
form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
|
||||
form.full_clean()
|
||||
self.assertEqual(form.errors, {'title': ['Title too long!!']})
|
||||
|
||||
def test_modelformset_factory_field_class_overrides(self):
|
||||
author = Author.objects.create(pk=1, name='Charles Baudelaire')
|
||||
BookFormSet = modelformset_factory(Book, fields="__all__", field_classes={
|
||||
'title': forms.SlugField,
|
||||
})
|
||||
form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
|
||||
self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
|
||||
self.assertIsInstance(form.fields['title'], forms.SlugField)
|
||||
|
||||
def test_inlineformset_factory_field_class_overrides(self):
|
||||
author = Author.objects.create(pk=1, name='Charles Baudelaire')
|
||||
BookFormSet = inlineformset_factory(Author, Book, fields="__all__", field_classes={
|
||||
'title': forms.SlugField,
|
||||
})
|
||||
form = BookFormSet.form(data={'title': 'Foo ' * 30, 'author': author.id})
|
||||
self.assertIs(Book._meta.get_field('title').__class__, models.CharField)
|
||||
self.assertIsInstance(form.fields['title'], forms.SlugField)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue