Ticket #17006: 17006.diff
File 17006.diff, 3.0 KB (added by , 12 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:: 307 307 By default a ``ModelForm`` is dynamically created for your model. It is 308 308 used to create the form presented on both the add/change pages. You can 309 309 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. 311 313 312 314 For an example see the section `Adding custom validation to the admin`_. 313 315 … … subclass:: 373 375 374 376 .. attribute:: ModelAdmin.inlines 375 377 376 See :class:`InlineModelAdmin` objects below. 378 See :class:`InlineModelAdmin` objects below as well as 379 :meth:`ModelAdmin.get_formsets`. 377 380 378 381 .. attribute:: ModelAdmin.list_display 379 382 … … templates used by the :class:`ModelAdmin` views: 1109 1112 1110 1113 (r'^my_view/$', self.admin_site.admin_view(self.my_view, cacheable=True)) 1111 1114 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 1112 1147 .. method:: ModelAdmin.formfield_for_foreignkey(self, db_field, request, **kwargs) 1113 1148 1114 1149 The ``formfield_for_foreignkey`` method on a ``ModelAdmin`` allows you to … … The ``InlineModelAdmin`` class adds: 1423 1458 through to ``inlineformset_factory`` when creating the formset for this 1424 1459 inline. 1425 1460 1426 .. _ref-contrib-admin-inline-extra:1427 1428 1461 .. attribute:: InlineModelAdmin.extra 1429 1462 1430 1463 This controls the number of extra forms the formset will display in