[1.6.x] Fixed #12346 -- Added a note on how to validate InlineFormSets.
Thanks johnsmith for the suggestion.
Backport of 181f63c22d
from master
This commit is contained in:
parent
0a84cbadb7
commit
cf8d0933cb
|
@ -1713,9 +1713,9 @@ The ``InlineModelAdmin`` class adds:
|
||||||
|
|
||||||
.. attribute:: InlineModelAdmin.formset
|
.. attribute:: InlineModelAdmin.formset
|
||||||
|
|
||||||
This defaults to ``BaseInlineFormSet``. Using your own formset can give you
|
This defaults to :class:`~django.forms.models.BaseInlineFormSet`. Using
|
||||||
many possibilities of customization. Inlines are built around
|
your own formset can give you many possibilities of customization. Inlines
|
||||||
:ref:`model formsets <model-formsets>`.
|
are built around :ref:`model formsets <model-formsets>`.
|
||||||
|
|
||||||
.. attribute:: InlineModelAdmin.form
|
.. attribute:: InlineModelAdmin.form
|
||||||
|
|
||||||
|
@ -1791,8 +1791,9 @@ The ``InlineModelAdmin`` class adds:
|
||||||
|
|
||||||
.. method:: InlineModelAdmin.get_formset(self, request, obj=None, **kwargs)
|
.. method:: InlineModelAdmin.get_formset(self, request, obj=None, **kwargs)
|
||||||
|
|
||||||
Returns a ``BaseInlineFormSet`` class for use in admin add/change views.
|
Returns a :class:`~django.forms.models.BaseInlineFormSet` class for use in
|
||||||
See the example for :class:`ModelAdmin.get_formsets`.
|
admin add/change views. See the example for
|
||||||
|
:class:`ModelAdmin.get_formsets`.
|
||||||
|
|
||||||
.. method:: InlineModelAdmin.get_extra(self, request, obj=None, **kwargs)
|
.. method:: InlineModelAdmin.get_extra(self, request, obj=None, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,8 @@ Model Form Functions
|
||||||
.. function:: inlineformset_factory(parent_model, model, form=ModelForm, formset=BaseInlineFormSet, fk_name=None, fields=None, exclude=None, extra=3, can_order=False, can_delete=True, max_num=None, formfield_callback=None, widgets=None, validate_max=False, localized_fields=None, labels=None, help_texts=None, error_messages=None)
|
.. function:: inlineformset_factory(parent_model, model, form=ModelForm, formset=BaseInlineFormSet, fk_name=None, fields=None, exclude=None, extra=3, can_order=False, can_delete=True, max_num=None, formfield_callback=None, widgets=None, validate_max=False, localized_fields=None, labels=None, help_texts=None, error_messages=None)
|
||||||
|
|
||||||
Returns an ``InlineFormSet`` using :func:`modelformset_factory` with
|
Returns an ``InlineFormSet`` using :func:`modelformset_factory` with
|
||||||
defaults of ``formset=BaseInlineFormSet``, ``can_delete=True``, and
|
defaults of ``formset=``:class:`~django.forms.models.BaseInlineFormSet`,
|
||||||
``extra=3``.
|
``can_delete=True``, and ``extra=3``.
|
||||||
|
|
||||||
If your model has more than one :class:`~django.db.models.ForeignKey` to
|
If your model has more than one :class:`~django.db.models.ForeignKey` to
|
||||||
the ``parent_model``, you must specify a ``fk_name``.
|
the ``parent_model``, you must specify a ``fk_name``.
|
||||||
|
|
|
@ -857,14 +857,16 @@ than that of a "normal" formset. The only difference is that we call
|
||||||
``formset.save()`` to save the data into the database. (This was described
|
``formset.save()`` to save the data into the database. (This was described
|
||||||
above, in :ref:`saving-objects-in-the-formset`.)
|
above, in :ref:`saving-objects-in-the-formset`.)
|
||||||
|
|
||||||
Overiding ``clean()`` on a ``model_formset``
|
.. _model-formsets-overriding-clean:
|
||||||
|
|
||||||
|
Overriding ``clean()`` on a ``ModelFormSet``
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
Just like with ``ModelForms``, by default the ``clean()`` method of a
|
Just like with ``ModelForms``, by default the ``clean()`` method of a
|
||||||
``model_formset`` will validate that none of the items in the formset violate
|
``ModelFormSet`` will validate that none of the items in the formset violate
|
||||||
the unique constraints on your model (either ``unique``, ``unique_together`` or
|
the unique constraints on your model (either ``unique``, ``unique_together`` or
|
||||||
``unique_for_date|month|year``). If you want to override the ``clean()`` method
|
``unique_for_date|month|year``). If you want to override the ``clean()`` method
|
||||||
on a ``model_formset`` and maintain this validation, you must call the parent
|
on a ``ModelFormSet`` and maintain this validation, you must call the parent
|
||||||
class's ``clean`` method::
|
class's ``clean`` method::
|
||||||
|
|
||||||
from django.forms.models import BaseModelFormSet
|
from django.forms.models import BaseModelFormSet
|
||||||
|
@ -969,6 +971,8 @@ primary key that isn't called ``id``, make sure it gets rendered.)
|
||||||
Inline formsets
|
Inline formsets
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
.. class:: models.BaseInlineFormSet
|
||||||
|
|
||||||
Inline formsets is a small abstraction layer on top of model formsets. These
|
Inline formsets is a small abstraction layer on top of model formsets. These
|
||||||
simplify the case of working with related objects via a foreign key. Suppose
|
simplify the case of working with related objects via a foreign key. Suppose
|
||||||
you have these two models::
|
you have these two models::
|
||||||
|
@ -1000,6 +1004,13 @@ a particular author, you could do this::
|
||||||
|
|
||||||
:ref:`Manually rendered can_delete and can_order <manually-rendered-can-delete-and-can-order>`.
|
:ref:`Manually rendered can_delete and can_order <manually-rendered-can-delete-and-can-order>`.
|
||||||
|
|
||||||
|
Overriding ``clean()`` on an ``InlineFormSet``
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
See :ref:`model-formsets-overriding-clean`, but subclass
|
||||||
|
:class:`~models.BaseInlineFormSet` rather than
|
||||||
|
:class:`~models.BaseModelFormSet`.
|
||||||
|
|
||||||
More than one foreign key to the same model
|
More than one foreign key to the same model
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue