1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Improved ImproperlyConfigured error message in ModelFormMixin.

Clarified that either 'fields' or 'form_class' attribute must be set
when using ModelFormMixin.
This commit is contained in:
Clifford Gama 2024-10-29 09:40:33 +02:00
parent 43287cbb87
commit 3e4527cc87
No known key found for this signature in database
GPG Key ID: BF895AA45E520E21
2 changed files with 4 additions and 3 deletions

View File

@ -101,8 +101,9 @@ class ModelFormMixin(FormMixin, SingleObjectMixin):
if self.fields is None:
raise ImproperlyConfigured(
"Using ModelFormMixin (base class of %s) without "
"the 'fields' attribute is prohibited." % self.__class__.__name__
"Using ModelFormMixin (base class of %s) without the 'fields' or "
"the 'form_class' attribute is prohibited."
% self.__class__.__name__
)
return model_forms.modelform_factory(model, fields=self.fields)

View File

@ -218,7 +218,7 @@ class CreateViewTests(TestCase):
message = (
"Using ModelFormMixin (base class of MyCreateView) without the "
"'fields' attribute is prohibited."
"'fields' or the 'form_class' attribute is prohibited."
)
with self.assertRaisesMessage(ImproperlyConfigured, message):
MyCreateView().get_form_class()