Ticket #17006: 17006.diff

File 17006.diff, 3.0 KB (added by timo, 2 years ago)
  • docs/ref/contrib/admin/index.txt

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    index 06751df..971db19 100644
    a b subclass:: 
    307307    By default a ``ModelForm`` is dynamically created for your model. It is
    308308    used to create the form presented on both the add/change pages. You can
    309309    easily provide your own ``ModelForm`` to override any default form behavior
    310     on the add/change pages.
     310    on the add/change pages. Alternatively, you can customize the default
     311    form rather than specifying an entirely new one by using the
     312    :meth:`ModelAdmin.get_form` method.
    311313
    312314    For an example see the section `Adding custom validation to the admin`_.
    313315
    subclass:: 
    373375
    374376.. attribute:: ModelAdmin.inlines
    375377
    376     See :class:`InlineModelAdmin` objects below.
     378    See :class:`InlineModelAdmin` objects below as well as
     379    :meth:`ModelAdmin.get_formsets`.
    377380
    378381.. attribute:: ModelAdmin.list_display
    379382
    templates used by the :class:`ModelAdmin` views: 
    11091112
    11101113        (r'^my_view/$', self.admin_site.admin_view(self.my_view, cacheable=True))
    11111114
     1115.. method:: ModelAdmin.get_form(self, request, obj=None, **kwargs)
     1116
     1117    Returns a :class:`~django.forms.ModelForm` class for use in the admin add
     1118    and change views, see :meth:`add_view` and :meth:`change_view`.
     1119
     1120    If you wanted to hide a field from non-superusers, for example, you could
     1121    override ``get_form`` as follows::
     1122
     1123        class MyModelAdmin(admin.ModelAdmin):
     1124            def get_form(self, request, obj=None, **kwargs):
     1125                self.exclude = []
     1126                if not request.user.is_superuser:
     1127                    self.exclude.append('field_to_hide')
     1128                return super(MyModelAdmin, self).get_form(request, obj, **kwargs)
     1129
     1130.. method:: ModelAdmin.get_formsets(self, request, obj=None)
     1131
     1132    Yields :class:`InlineModelAdmin`\s for use in admin add and change views.
     1133
     1134    For example if you wanted to display a particular inline only in the change
     1135    view, you could override ``get_formsets`` as follows::
     1136
     1137        class MyModelAdmin(admin.ModelAdmin):
     1138            inlines = [MyInline, SomeOtherInline]
     1139
     1140            def get_formsets(self, request, obj=None):
     1141                for inline in self.get_inline_instances():
     1142                    # hide MyInline in the add view
     1143                    if isinstance(inline, MyInline) and obj is None:
     1144                        continue
     1145                    yield inline.get_formset(request, obj)
     1146
    11121147.. method:: ModelAdmin.formfield_for_foreignkey(self, db_field, request, **kwargs)
    11131148
    11141149    The ``formfield_for_foreignkey`` method on a ``ModelAdmin`` allows you to
    The ``InlineModelAdmin`` class adds: 
    14231458    through to ``inlineformset_factory`` when creating the formset for this
    14241459    inline.
    14251460
    1426     .. _ref-contrib-admin-inline-extra:
    1427 
    14281461.. attribute:: InlineModelAdmin.extra
    14291462
    14301463    This controls the number of extra forms the formset will display in
Back to Top