mirror of https://github.com/django/django.git
Improvement on InlineFormSet doc, refs #21006
This commit is contained in:
parent
9bfe66164e
commit
944a2bb7c1
|
@ -938,7 +938,7 @@ class's ``clean`` method::
|
||||||
class MyModelFormSet(BaseModelFormSet):
|
class MyModelFormSet(BaseModelFormSet):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super(MyModelFormSet, self).clean()
|
super(MyModelFormSet, self).clean()
|
||||||
# example custom validation across forms in the formset:
|
# example custom validation across forms in the formset
|
||||||
for form in self.forms:
|
for form in self.forms:
|
||||||
# your custom formset validation
|
# your custom formset validation
|
||||||
...
|
...
|
||||||
|
@ -1075,14 +1075,14 @@ When overriding methods on ``InlineFormSet``, you should subclass
|
||||||
:class:`~models.BaseInlineFormSet` rather than
|
:class:`~models.BaseInlineFormSet` rather than
|
||||||
:class:`~models.BaseModelFormSet`.
|
:class:`~models.BaseModelFormSet`.
|
||||||
|
|
||||||
For example, If you want to override ``clean()``::
|
For example, if you want to override ``clean()``::
|
||||||
|
|
||||||
from django.forms.models import BaseInlineFormSet
|
from django.forms.models import BaseInlineFormSet
|
||||||
|
|
||||||
class MyModelFormSet(BaseInlineFormSet):
|
class CustomInlineFormSet(BaseInlineFormSet):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super(MyModelFormSet, self).clean()
|
super(CustomInlineFormSet, self).clean()
|
||||||
# example custom validation across forms in the formset:
|
# example custom validation across forms in the formset
|
||||||
for form in self.forms:
|
for form in self.forms:
|
||||||
# your custom formset validation
|
# your custom formset validation
|
||||||
...
|
...
|
||||||
|
@ -1093,7 +1093,7 @@ Then when you create your inline formset, pass in the optional argument
|
||||||
``formset``::
|
``formset``::
|
||||||
|
|
||||||
>>> from django.forms.models import inlineformset_factory
|
>>> from django.forms.models import inlineformset_factory
|
||||||
>>> BookFormSet = inlineformset_factory(Author, Book, formset=MyModelFormSet)
|
>>> BookFormSet = inlineformset_factory(Author, Book, formset=CustomInlineFormSet)
|
||||||
>>> author = Author.objects.get(name=u'Mike Royko')
|
>>> author = Author.objects.get(name=u'Mike Royko')
|
||||||
>>> formset = BookFormSet(instance=author)
|
>>> formset = BookFormSet(instance=author)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue