From 299983616ffc146a6f5aa03af9b3f4a56853f05c Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sun, 23 Jun 2013 23:43:09 +0200 Subject: [PATCH] Fixed #20644 -- Add ModelFormMixin.fields to the CBV flattened index Thanks to Tim Graham for the report and review. --- django/views/generic/edit.py | 6 +++--- docs/ref/class-based-views/flattened-index.txt | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py index 193071efc5..fccacf0bd3 100644 --- a/django/views/generic/edit.py +++ b/django/views/generic/edit.py @@ -89,6 +89,7 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): """ A mixin that provides a way to show and handle a modelform in a request. """ + fields = None def get_form_class(self): """ @@ -109,13 +110,12 @@ class ModelFormMixin(FormMixin, SingleObjectMixin): # from that model = self.get_queryset().model - fields = getattr(self, 'fields', None) - if fields is None: + if self.fields is None: warnings.warn("Using ModelFormMixin (base class of %s) without " "the 'fields' attribute is deprecated." % self.__class__.__name__, PendingDeprecationWarning) - return model_forms.modelform_factory(model, fields=fields) + return model_forms.modelform_factory(model, fields=self.fields) def get_form_kwargs(self): """ diff --git a/docs/ref/class-based-views/flattened-index.txt b/docs/ref/class-based-views/flattened-index.txt index df00f87aa0..7634a07300 100644 --- a/docs/ref/class-based-views/flattened-index.txt +++ b/docs/ref/class-based-views/flattened-index.txt @@ -177,6 +177,7 @@ CreateView * :attr:`~django.views.generic.base.TemplateResponseMixin.content_type` * :attr:`~django.views.generic.detail.SingleObjectMixin.context_object_name` [:meth:`~django.views.generic.detail.SingleObjectMixin.get_context_object_name`] +* :attr:`~django.views.generic.edit.ModelFormMixin.fields` * :attr:`~django.views.generic.edit.FormMixin.form_class` [:meth:`~django.views.generic.edit.FormMixin.get_form_class`] * :attr:`~django.views.generic.base.View.http_method_names` * :attr:`~django.views.generic.edit.FormMixin.initial` [:meth:`~django.views.generic.edit.FormMixin.get_initial`] @@ -216,6 +217,7 @@ UpdateView * :attr:`~django.views.generic.base.TemplateResponseMixin.content_type` * :attr:`~django.views.generic.detail.SingleObjectMixin.context_object_name` [:meth:`~django.views.generic.detail.SingleObjectMixin.get_context_object_name`] +* :attr:`~django.views.generic.edit.ModelFormMixin.fields` * :attr:`~django.views.generic.edit.FormMixin.form_class` [:meth:`~django.views.generic.edit.FormMixin.get_form_class`] * :attr:`~django.views.generic.base.View.http_method_names` * :attr:`~django.views.generic.edit.FormMixin.initial` [:meth:`~django.views.generic.edit.FormMixin.get_initial`]