Ticket #8861: 8861-self_instance_model_form_attribute.diff

File 8861-self_instance_model_form_attribute.diff, 2.5 KB (added by Ramiro Morales, 15 years ago)

Patch that adds a blurb to the relevant section of topics/forms/modelforms (rather than of forms/validation/#ref-forms-validation) and a link to it from ref/contrib/admin/index

  • docs/ref/contrib/admin/index.txt

    diff -r 95d590521fb4 docs/ref/contrib/admin/index.txt
    a b  
    783783-------------------------------------
    784784
    785785Adding custom validation of data in the admin is quite easy. The automatic admin
    786 interfaces reuses :mod:`django.forms`, and the ``ModelAdmin`` class gives you
     786interface reuses :mod:`django.forms`, and the ``ModelAdmin`` class gives you
    787787the ability define your own form::
    788788
    789789    class ArticleAdmin(admin.ModelAdmin):
     
    803803
    804804It is important you use a ``ModelForm`` here otherwise things can break. See the
    805805:ref:`forms <ref-forms-index>` documentation on :ref:`custom validation
    806 <ref-forms-validation>` for more information.
     806<ref-forms-validation>` and, more specifically, the
     807:ref:`model form validation notes <overriding-modelform-clean-method>` for more
     808information.
    807809
    808810.. _admin-inlines:
    809811
  • docs/topics/forms/modelforms.txt

    diff -r 95d590521fb4 docs/topics/forms/modelforms.txt
    a b  
    397397    ...         model = Book
    398398    ...         fields = ['title', 'author']
    399399
     400.. _overriding-modelform-clean-method:
    400401
    401402Overriding the clean() method
    402403-----------------------------
    403404
    404405You can override the ``clean()`` method on a model form to provide additional
    405 validation in the same way you can on a normal form. However, by default the
    406 ``clean()`` method validates the uniqueness of fields that are marked as
    407 ``unique``, ``unique_together`` or ``unique_for_date|month|year`` on the model.
    408 Therefore, if you would like to override the ``clean()`` method and maintain the
    409 default validation, you must call the parent class's ``clean()`` method.
     406validation in the same way you can on a normal form.
     407
     408In this regard, model forms have two specific characteristics when compared to
     409forms:
     410
     411By default the ``clean()`` method validates the uniqueness of fields that are
     412marked as ``unique``, ``unique_together`` or ``unique_for_date|month|year`` on
     413the model.  Therefore, if you would like to override the ``clean()`` method and
     414maintain the default validation, you must call the parent class's ``clean()``
     415method.
     416
     417Also, a model form instance bound to a model object will contain a
     418``self.instance`` attribute that gives model form methods access to that
     419specific model instance.
    410420
    411421Form inheritance
    412422----------------
Back to Top