summaryrefslogtreecommitdiff
path: root/docs/ref/contrib/admin
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2013-02-21 21:56:55 +0000
committerLuke Plant <L.Plant.98@cantab.net>2013-05-09 16:44:36 +0100
commitf026a519aea8f3ea7ca339bfbbb007e1ee0068b0 (patch)
tree882e594178a78d507ede36c2c9b0b8d5a9305561 /docs/ref/contrib/admin
parent1e37cb37cec330a6b78925e2ef5589817428d09a (diff)
Fixed #19733 - deprecated ModelForms without 'fields' or 'exclude', and added '__all__' shortcut
This also updates all dependent functionality, including modelform_factory and modelformset_factory, and the generic views `ModelFormMixin`, `CreateView` and `UpdateView` which gain a new `fields` attribute.
Diffstat (limited to 'docs/ref/contrib/admin')
-rw-r--r--docs/ref/contrib/admin/index.txt34
1 files changed, 29 insertions, 5 deletions
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 43f0398566..67e498ee91 100644
--- a/docs/ref/contrib/admin/index.txt
+++ b/docs/ref/contrib/admin/index.txt
@@ -337,6 +337,22 @@ subclass::
.. admonition:: Note
+ .. versionchanged:: 1.6
+
+ If you define the ``Meta.model`` attribute on a
+ :class:`~django.forms.ModelForm`, you must also define the
+ ``Meta.fields`` attribute (or the ``Meta.exclude`` attribute). However,
+ since the admin has its own way of defining fields, the ``Meta.fields``
+ attribute will be ignored.
+
+ If the ``ModelForm`` is only going to be used for the admin, the easiest
+ solution is to omit the ``Meta.model`` attribute, since ``ModelAdmin``
+ will provide the correct model to use. Alternatively, you can set
+ ``fields = []`` in the ``Meta`` class to satisfy the validation on the
+ ``ModelForm``.
+
+ .. admonition:: Note
+
If your ``ModelForm`` and ``ModelAdmin`` both define an ``exclude``
option then ``ModelAdmin`` takes precedence::
@@ -1283,13 +1299,24 @@ templates used by the :class:`ModelAdmin` views:
on the changelist page. To use a custom form, for example::
class MyForm(forms.ModelForm):
- class Meta:
- model = MyModel
+ pass
class MyModelAdmin(admin.ModelAdmin):
def get_changelist_form(self, request, **kwargs):
return MyForm
+ .. admonition:: Note
+
+ .. versionchanged:: 1.6
+
+ If you define the ``Meta.model`` attribute on a
+ :class:`~django.forms.ModelForm`, you must also define the
+ ``Meta.fields`` attribute (or the ``Meta.exclude`` attribute). However,
+ ``ModelAdmin`` ignores this value, overriding it with the
+ :attr:`ModelAdmin.list_editable` attribute. The easiest solution is to
+ omit the ``Meta.model`` attribute, since ``ModelAdmin`` will provide the
+ correct model to use.
+
.. method:: ModelAdmin.get_changelist_formset(self, request, **kwargs)
Returns a :ref:`ModelFormSet <model-formsets>` class for use on the
@@ -1490,9 +1517,6 @@ needed. Now within your form you can add your own custom validation for
any field::
class MyArticleAdminForm(forms.ModelForm):
- class Meta:
- model = Article
-
def clean_name(self):
# do something that validates your data
return self.cleaned_data["name"]