From 3e4527cc87a34faf13335605a7da41b907115e6d Mon Sep 17 00:00:00 2001 From: Clifford Gama Date: Tue, 29 Oct 2024 09:40:33 +0200 Subject: [PATCH] Improved ImproperlyConfigured error message in ModelFormMixin. Clarified that either 'fields' or 'form_class' attribute must be set when using ModelFormMixin. --- django/views/generic/edit.py | 5 +++-- tests/generic_views/test_edit.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index ebd071cf00..20189130de 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -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) diff --git a/tests/generic_views/test_edit.py b/tests/generic_views/test_edit.py index 09d887ae92..ce286f22b8 100644 --- a/tests/generic_views/test_edit.py +++ b/tests/generic_views/test_edit.py @@ -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()