~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to docs/ref/contrib/admin/index.txt

  • Committer: Package Import Robot
  • Author(s): Luke Faraone, Jakub Wilk, Luke Faraone
  • Date: 2013-05-09 15:10:47 UTC
  • mfrom: (1.1.21) (4.4.27 sid)
  • Revision ID: package-import@ubuntu.com-20130509151047-aqv8d71oj9wvcv8c
Tags: 1.5.1-2
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Luke Faraone ]
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
   in your :setting:`INSTALLED_APPS` list, add them.
27
27
 
28
28
3. Add ``django.contrib.messages.context_processors.messages`` to
29
 
   :setting:`TEMPLATE_CONTEXT_PROCESSORS` and
30
 
   :class:`~django.contrib.messages.middleware.MessageMiddleware` to
31
 
   :setting:`MIDDLEWARE_CLASSES`. (These are both active by default, so
 
29
   :setting:`TEMPLATE_CONTEXT_PROCESSORS` as well as
 
30
   :class:`django.contrib.auth.middleware.AuthenticationMiddleware` and
 
31
   :class:`django.contrib.messages.middleware.MessageMiddleware` to
 
32
   :setting:`MIDDLEWARE_CLASSES`. (These are all active by default, so
32
33
   you only need to do this if you've manually tweaked the settings.)
33
34
 
34
35
4. Determine which of your application's models should be editable in the
60
61
    For information about serving the static files (images, JavaScript, and
61
62
    CSS) associated with the admin in production, see :ref:`serving-files`.
62
63
 
 
64
    Having problems?  Try :doc:`/faq/admin`.
 
65
 
63
66
``ModelAdmin`` objects
64
67
======================
65
68
 
115
118
 
116
119
.. attribute:: ModelAdmin.actions_selection_counter
117
120
 
118
 
    .. versionadded:: 1.2
119
 
 
120
 
    Controls whether a selection counter is display next to the action dropdown.
 
121
    Controls whether a selection counter is displayed next to the action dropdown.
121
122
    By default, the admin changelist will display it
122
123
    (``actions_selection_counter = True``).
123
124
 
131
132
 
132
133
        date_hierarchy = 'pub_date'
133
134
 
134
 
    .. versionadded:: 1.3
135
 
 
136
135
    This will intelligently populate itself based on available data,
137
136
    e.g. if all the dates are in one month, it'll show the day-level
138
137
    drill-down only.
171
170
    ``fields`` option (for more complex layout needs see the
172
171
    :attr:`~ModelAdmin.fieldsets` option described in the next section). For
173
172
    example, you could define a simpler version of the admin form for the
174
 
    ``django.contrib.flatpages.FlatPage`` model as follows::
 
173
    :class:`django.contrib.flatpages.models.FlatPage` model as follows::
175
174
 
176
175
        class FlatPageAdmin(admin.ModelAdmin):
177
176
            fields = ('url', 'title', 'content')
178
177
 
179
178
    In the above example, only the fields ``url``, ``title`` and ``content``
180
 
    will be displayed, sequentially, in the form.
181
 
 
182
 
    .. versionadded:: 1.2
183
 
 
184
 
    ``fields`` can contain values defined in :attr:`ModelAdmin.readonly_fields`
185
 
    to be displayed as read-only.
 
179
    will be displayed, sequentially, in the form. ``fields`` can contain
 
180
    values defined in :attr:`ModelAdmin.readonly_fields` to be displayed as
 
181
    read-only.
 
182
 
 
183
    The ``fields`` option, unlike :attr:`~ModelAdmin.list_display`, may only
 
184
    contain names of fields on the model or the form specified by
 
185
    :attr:`~ModelAdmin.form`. It may contain callables only if they are listed
 
186
    in :attr:`~ModelAdmin.readonly_fields`.
186
187
 
187
188
    .. versionadded:: 1.4
188
189
 
218
219
    a dictionary of information about the fieldset, including a list of fields
219
220
    to be displayed in it.
220
221
 
221
 
    A full example, taken from the :class:`django.contrib.flatpages.FlatPage`
222
 
    model::
 
222
    A full example, taken from the
 
223
    :class:`django.contrib.flatpages.models.FlatPage` model::
223
224
 
224
225
        class FlatPageAdmin(admin.ModelAdmin):
225
226
            fieldsets = (
253
254
            'fields': ('first_name', 'last_name', 'address', 'city', 'state'),
254
255
            }
255
256
 
256
 
        Just like with the :attr:`~ModelAdmin.fields` option, to display
257
 
        multiple fields on the same line, wrap those fields in their own
258
 
        tuple. In this example, the ``first_name`` and ``last_name`` fields
259
 
        will display on the same line::
 
257
        As with the :attr:`~ModelAdmin.fields` option, to display multiple
 
258
        fields on the same line, wrap those fields in their own tuple. In this
 
259
        example, the ``first_name`` and ``last_name`` fields will display on
 
260
        the same line::
260
261
 
261
262
            {
262
263
            'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),
263
264
            }
264
265
 
265
 
        .. versionadded:: 1.2
266
 
 
267
266
        ``fields`` can contain values defined in
268
267
        :attr:`~ModelAdmin.readonly_fields` to be displayed as read-only.
269
268
 
 
269
        If you add the name of a callable to ``fields``, the same rule applies
 
270
        as with the :attr:`~ModelAdmin.fields` option: the callable must be
 
271
        listed in :attr:`~ModelAdmin.readonly_fields`.
 
272
 
270
273
    * ``classes``
271
274
        A list containing extra CSS classes to apply to the fieldset.
272
275
 
365
368
 
366
369
    Note that the key in the dictionary is the actual field class, *not* a
367
370
    string. The value is another dictionary; these arguments will be passed to
368
 
    :meth:`~django.forms.Field.__init__`. See :doc:`/ref/forms/api` for
 
371
    the form field's ``__init__()`` method. See :doc:`/ref/forms/api` for
369
372
    details.
370
373
 
371
374
    .. warning::
457
460
    * If the string given is a method of the model, ``ModelAdmin`` or a
458
461
      callable, Django will HTML-escape the output by default. If you'd
459
462
      rather not escape the output of the method, give the method an
460
 
      ``allow_tags`` attribute whose value is ``True``.
 
463
      ``allow_tags`` attribute whose value is ``True``. However, to avoid an
 
464
      XSS vulnerability, you should use :func:`~django.utils.html.format_html`
 
465
      to escape user-provided inputs.
461
466
 
462
467
      Here's a full example model::
463
468
 
 
469
          from django.utils.html import format_html
 
470
 
464
471
          class Person(models.Model):
465
472
              first_name = models.CharField(max_length=50)
466
473
              last_name = models.CharField(max_length=50)
467
474
              color_code = models.CharField(max_length=6)
468
475
 
469
476
              def colored_name(self):
470
 
                  return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
 
477
                  return format_html('<span style="color: #{0};">{1} {2}</span>',
 
478
                                     self.color_code,
 
479
                                     self.first_name,
 
480
                                     self.last_name)
 
481
 
471
482
              colored_name.allow_tags = True
472
483
 
473
484
          class PersonAdmin(admin.ModelAdmin):
508
519
 
509
520
      For example::
510
521
 
 
522
        from django.utils.html import format_html
 
523
 
511
524
        class Person(models.Model):
512
525
            first_name = models.CharField(max_length=50)
513
526
            color_code = models.CharField(max_length=6)
514
527
 
515
528
            def colored_first_name(self):
516
 
                return '<span style="color: #%s;">%s</span>' % (self.color_code, self.first_name)
 
529
                return format_html('<span style="color: #{0};">{1}</span>',
 
530
                                   self.color_code,
 
531
                                   self.first_name)
 
532
 
517
533
            colored_first_name.allow_tags = True
518
534
            colored_first_name.admin_order_field = 'first_name'
519
535
 
576
592
 
577
593
    .. image:: _images/users_changelist.png
578
594
 
579
 
    ``list_filter`` should be a list of elements, where each element should be
580
 
    of one of the following types:
 
595
    ``list_filter`` should be a list or tuple of elements, where each element
 
596
    should be of one of the following types:
581
597
 
582
598
    * a field name, where the specified field should be either a
583
599
      ``BooleanField``, ``CharField``, ``DateField``, ``DateTimeField``,
586
602
          class PersonAdmin(ModelAdmin):
587
603
              list_filter = ('is_staff', 'company')
588
604
 
589
 
      .. versionadded:: 1.3
590
 
 
591
605
      Field names in ``list_filter`` can also span relations
592
606
      using the ``__`` lookup, for example::
593
607
 
596
610
 
597
611
    .. versionadded:: 1.4
598
612
 
599
 
    * a class inheriting from :mod:`django.contrib.admin.SimpleListFilter`,
 
613
    * a class inheriting from ``django.contrib.admin.SimpleListFilter``,
600
614
      which you need to provide the ``title`` and ``parameter_name``
601
615
      attributes to and override the ``lookups`` and ``queryset`` methods,
602
616
      e.g.::
633
647
                   provided in the query string and retrievable via
634
648
                   `self.value()`.
635
649
                   """
636
 
                   # Compare the requested value (either '80s' or 'other')
 
650
                   # Compare the requested value (either '80s' or '90s')
637
651
                   # to decide how to filter the queryset.
638
652
                   if self.value() == '80s':
639
653
                       return queryset.filter(birthday__gte=date(1980, 1, 1),
685
699
 
686
700
    * a tuple, where the first element is a field name and the second
687
701
      element is a class inheriting from
688
 
      :mod:`django.contrib.admin.FieldListFilter`, for example::
 
702
      ``django.contrib.admin.FieldListFilter``, for example::
689
703
 
690
704
          from django.contrib.admin import BooleanFieldListFilter
691
705
 
758
772
 
759
773
.. attribute:: ModelAdmin.paginator
760
774
 
761
 
    .. versionadded:: 1.3
762
 
 
763
775
    The paginator class to be used for pagination. By default,
764
776
    :class:`django.core.paginator.Paginator` is used. If the custom paginator
765
777
    class doesn't have the same constructor interface as
824
836
 
825
837
.. attribute:: ModelAdmin.readonly_fields
826
838
 
827
 
    .. versionadded:: 1.2
828
 
 
829
839
    By default the admin shows all fields as editable. Any fields in this
830
840
    option (which should be a ``list`` or ``tuple``) will display its data
831
 
    as-is and non-editable. This option behaves nearly identical to
832
 
    :attr:`ModelAdmin.list_display`. Usage is the same, however, when you
833
 
    specify :attr:`ModelAdmin.fields` or :attr:`ModelAdmin.fieldsets` the
834
 
    read-only fields must be present to be shown (they are ignored otherwise).
 
841
    as-is and non-editable; they are also excluded from the
 
842
    :class:`~django.forms.ModelForm` used for creating and editing. Note that
 
843
    when specifying :attr:`ModelAdmin.fields` or :attr:`ModelAdmin.fieldsets`
 
844
    the read-only fields must be present to be shown (they are ignored
 
845
    otherwise).
835
846
 
836
847
    If ``readonly_fields`` is used without defining explicit ordering through
837
848
    :attr:`ModelAdmin.fields` or :attr:`ModelAdmin.fieldsets` they will be
838
849
    added last after all editable fields.
839
850
 
 
851
    A read-only field can not only display data from a model's field, it can
 
852
    also display the output of a model's method or a method of the
 
853
    ``ModelAdmin`` class itself. This is very similar to the way
 
854
    :attr:`ModelAdmin.list_display` behaves. This provides an easy way to use
 
855
    the admin interface to provide feedback on the status of the objects being
 
856
    edited, for example::
 
857
 
 
858
        from django.utils.html import format_html_join
 
859
        from django.utils.safestring import mark_safe
 
860
 
 
861
        class PersonAdmin(ModelAdmin):
 
862
            readonly_fields = ('address_report',)
 
863
 
 
864
            def address_report(self, instance):
 
865
                # assuming get_full_address() returns a list of strings
 
866
                # for each line of the address and you want to separate each
 
867
                # line by a linebreak
 
868
                return format_html_join(
 
869
                    mark_safe('<br/>'),
 
870
                    '{0}',
 
871
                    ((line,) for line in instance.get_full_address()),
 
872
                ) or "<span class='errors'>I can't determine this address.</span>"
 
873
 
 
874
            # short_description functions like a model field's verbose_name
 
875
            address_report.short_description = "Address"
 
876
            # in this example, we have used HTML tags in the output
 
877
            address_report.allow_tags = True
 
878
 
840
879
.. attribute:: ModelAdmin.save_as
841
880
 
842
881
    Set ``save_as`` to enable a "save as" feature on admin change forms.
933
972
 
934
973
.. attribute:: ModelAdmin.add_form_template
935
974
 
936
 
    .. versionadded:: 1.2
937
 
 
938
975
    Path to a custom template, used by :meth:`add_view`.
939
976
 
940
977
.. attribute:: ModelAdmin.change_form_template
952
989
 
953
990
.. attribute:: ModelAdmin.delete_selected_confirmation_template
954
991
 
955
 
    .. versionadded:: 1.2
956
 
 
957
 
    Path to a custom template, used by the :meth:`delete_selected`
958
 
    action method for displaying a confirmation page when deleting one
959
 
    or more objects. See the :doc:`actions
960
 
    documentation</ref/contrib/admin/actions>`.
 
992
    Path to a custom template, used by the ``delete_selected`` action method
 
993
    for displaying a confirmation page when deleting one or more objects. See
 
994
    the :doc:`actions documentation</ref/contrib/admin/actions>`.
961
995
 
962
996
.. attribute:: ModelAdmin.object_history_template
963
997
 
990
1024
 
991
1025
.. method:: ModelAdmin.delete_model(self, request, obj)
992
1026
 
993
 
    .. versionadded:: 1.3
994
 
 
995
1027
    The ``delete_model`` method is given the ``HttpRequest`` and a model
996
1028
    instance. Use this method to do pre- or post-delete operations.
997
1029
 
1040
1072
 
1041
1073
.. method:: ModelAdmin.get_readonly_fields(self, request, obj=None)
1042
1074
 
1043
 
    .. versionadded:: 1.2
1044
 
 
1045
1075
    The ``get_readonly_fields`` method is given the ``HttpRequest`` and the
1046
1076
    ``obj`` being edited (or ``None`` on an add form) and is expected to return
1047
1077
    a ``list`` or ``tuple`` of field names that will be displayed as read-only,
1075
1105
    changelist that will be linked to the change view, as described in the
1076
1106
    :attr:`ModelAdmin.list_display_links` section.
1077
1107
 
 
1108
.. method:: ModelAdmin.get_fieldsets(self, request, obj=None)
 
1109
 
 
1110
    The ``get_fieldsets`` method is given the ``HttpRequest`` and the ``obj``
 
1111
    being edited (or ``None`` on an add form) and is expected to return a list
 
1112
    of two-tuples, in which each two-tuple represents a ``<fieldset>`` on the
 
1113
    admin form page, as described above in the :attr:`ModelAdmin.fieldsets` section.
 
1114
 
 
1115
.. method:: ModelAdmin.get_list_filter(self, request)
 
1116
 
 
1117
    .. versionadded:: 1.5
 
1118
 
 
1119
    The ``get_list_filter`` method is given the ``HttpRequest`` and is expected
 
1120
    to return the same kind of sequence type as for the
 
1121
    :attr:`~ModelAdmin.list_filter` attribute.
 
1122
 
 
1123
.. method:: ModelAdmin.get_inline_instances(self, request, obj=None)
 
1124
 
 
1125
    .. versionadded:: 1.5
 
1126
 
 
1127
    The ``get_inline_instances`` method is given the ``HttpRequest`` and the
 
1128
    ``obj`` being edited (or ``None`` on an add form) and is expected to return
 
1129
    a ``list`` or ``tuple`` of :class:`~django.contrib.admin.InlineModelAdmin`
 
1130
    objects, as described below in the :class:`~django.contrib.admin.InlineModelAdmin`
 
1131
    section.
 
1132
 
1078
1133
.. method:: ModelAdmin.get_urls(self)
1079
1134
 
1080
1135
    The ``get_urls`` method on a ``ModelAdmin`` returns the URLs to be used for
1115
1170
 
1116
1171
    Since this is usually not what you want, Django provides a convenience
1117
1172
    wrapper to check permissions and mark the view as non-cacheable. This
1118
 
    wrapper is :meth:`AdminSite.admin_view` (i.e.
1119
 
    ``self.admin_site.admin_view`` inside a ``ModelAdmin`` instance); use it
1120
 
    like so::
 
1173
    wrapper is ``AdminSite.admin_view()`` (i.e. ``self.admin_site.admin_view``
 
1174
    inside a ``ModelAdmin`` instance); use it like so::
1121
1175
 
1122
1176
        class MyModelAdmin(admin.ModelAdmin):
1123
1177
            def get_urls(self):
1137
1191
 
1138
1192
    If the page is cacheable, but you still want the permission check to be
1139
1193
    performed, you can pass a ``cacheable=True`` argument to
1140
 
    :meth:`AdminSite.admin_view`::
 
1194
    ``AdminSite.admin_view()``::
1141
1195
 
1142
1196
        (r'^my_view/$', self.admin_site.admin_view(self.my_view, cacheable=True))
1143
1197
 
1167
1221
            inlines = [MyInline, SomeOtherInline]
1168
1222
 
1169
1223
            def get_formsets(self, request, obj=None):
1170
 
                for inline in self.get_inline_instances(request):
 
1224
                for inline in self.get_inline_instances(request, obj):
1171
1225
                    # hide MyInline in the add view
1172
1226
                    if isinstance(inline, MyInline) and obj is None:
1173
1227
                        continue
1224
1278
 
1225
1279
.. method:: ModelAdmin.get_changelist(self, request, **kwargs)
1226
1280
 
1227
 
    Returns the Changelist class to be used for listing. By default,
 
1281
    Returns the ``Changelist`` class to be used for listing. By default,
1228
1282
    ``django.contrib.admin.views.main.ChangeList`` is used. By inheriting this
1229
1283
    class you can change the behavior of the listing.
1230
1284
 
 
1285
.. method:: ModelAdmin.get_changelist_form(self, request, **kwargs)
 
1286
 
 
1287
    Returns a :class:`~django.forms.ModelForm` class for use in the ``Formset``
 
1288
    on the changelist page. To use a custom form, for example::
 
1289
 
 
1290
        class MyForm(forms.ModelForm):
 
1291
            class Meta:
 
1292
                model = MyModel
 
1293
 
 
1294
        class MyModelAdmin(admin.ModelAdmin):
 
1295
            def get_changelist_form(self, request, **kwargs):
 
1296
                return MyForm
 
1297
 
 
1298
.. method::  ModelAdmin.get_changelist_formset(self, request, **kwargs)
 
1299
 
 
1300
    Returns a :ref:`ModelFormSet <model-formsets>` class for use on the
 
1301
    changelist page if :attr:`~ModelAdmin.list_editable` is used. To use a
 
1302
    custom formset, for example::
 
1303
 
 
1304
        from django.forms.models import BaseModelFormSet
 
1305
 
 
1306
        class MyAdminFormSet(BaseModelFormSet):
 
1307
            pass
 
1308
 
 
1309
        class MyModelAdmin(admin.ModelAdmin):
 
1310
            def get_changelist_formset(self, request, **kwargs):
 
1311
                kwargs['formset'] = MyAdminFormSet
 
1312
                return super(MyModelAdmin, self).get_changelist_formset(request, **kwargs)
 
1313
 
1231
1314
.. method:: ModelAdmin.has_add_permission(self, request)
1232
1315
 
1233
1316
    Should return ``True`` if adding an object is permitted, ``False``
1263
1346
                    return qs
1264
1347
                return qs.filter(author=request.user)
1265
1348
 
1266
 
.. method:: ModelAdmin.message_user(request, message)
1267
 
 
1268
 
    Sends a message to the user. The default implementation creates a message
1269
 
    using the :mod:`django.contrib.messages` backend. See the
1270
 
    :ref:`custom ModelAdmin example <custom-admin-action>`.
 
1349
.. method:: ModelAdmin.message_user(request, message, level=messages.INFO, extra_tags='', fail_silently=False)
 
1350
 
 
1351
    Sends a message to the user using the :mod:`django.contrib.messages`
 
1352
    backend.  See the :ref:`custom ModelAdmin example <custom-admin-action>`.
 
1353
 
 
1354
    .. versionadded:: 1.5
 
1355
 
 
1356
    Keyword arguments allow you to change the message level, add extra CSS
 
1357
    tags, or fail silently if the ``contrib.messages`` framework is not
 
1358
    installed. These keyword arguments match those for
 
1359
    :func:`django.contrib.messages.add_message`, see that function's
 
1360
    documentation for more details. One difference is that the level may be
 
1361
    passed as a string label in addition to integer/constant.
1271
1362
 
1272
1363
.. method:: ModelAdmin.get_paginator(queryset, per_page, orphans=0, allow_empty_first_page=True)
1273
1364
 
1274
 
    .. versionadded:: 1.3
1275
 
 
1276
1365
    Returns an instance of the paginator to use for this view. By default,
1277
1366
    instantiates an instance of :attr:`paginator`.
1278
1367
 
1339
1428
rendering. For more details, see the
1340
1429
:doc:`TemplateResponse documentation </ref/template-response>`.
1341
1430
 
 
1431
.. _modeladmin-media-definitions:
 
1432
 
1342
1433
``ModelAdmin`` media definitions
1343
1434
--------------------------------
1344
1435
 
1353
1444
            }
1354
1445
            js = ("my_code.js",)
1355
1446
 
1356
 
.. versionchanged:: 1.3
1357
 
 
1358
1447
The :doc:`staticfiles app </ref/contrib/staticfiles>` prepends
1359
1448
:setting:`STATIC_URL` (or :setting:`MEDIA_URL` if :setting:`STATIC_URL` is
1360
1449
``None``) to any media paths. The same rules apply as :ref:`regular media
1361
1450
definitions on forms <form-media-paths>`.
1362
1451
 
1363
 
Django admin Javascript makes use of the `jQuery`_ library. To avoid
1364
 
conflicts with user-supplied scripts or libraries, Django's jQuery is
1365
 
namespaced as ``django.jQuery``. If you want to use jQuery in your own admin
1366
 
JavaScript without including a second copy, you can use the ``django.jQuery``
1367
 
object on changelist and add/edit views.
1368
 
 
1369
 
If you require the jQuery library to be in the global namespace, for example
1370
 
when using third-party jQuery plugins, or need a newer version of jQuery, you
1371
 
will have to include your own copy of jQuery.
 
1452
jQuery
 
1453
~~~~~~
 
1454
 
 
1455
Django admin Javascript makes use of the `jQuery`_ library.
 
1456
 
 
1457
To avoid conflicts with user-supplied scripts or libraries, Django's jQuery
 
1458
(version 1.4.2) is namespaced as ``django.jQuery``. If you want to use jQuery
 
1459
in your own admin JavaScript without including a second copy, you can use the
 
1460
``django.jQuery`` object on changelist and add/edit views.
 
1461
 
 
1462
The :class:`ModelAdmin` class requires jQuery by default, so there is no need
 
1463
to add jQuery to your ``ModelAdmin``'s list of media resources unless you have
 
1464
a specifc need. For example, if you require the jQuery library to be in the
 
1465
global namespace (for example when using third-party jQuery plugins) or if you
 
1466
need a newer version of jQuery, you will have to include your own copy.
 
1467
 
 
1468
Django provides both uncompressed and 'minified' versions of jQuery, as
 
1469
``jquery.js`` and ``jquery.min.js`` respectively.
 
1470
 
 
1471
:class:`ModelAdmin` and :class:`InlineModelAdmin` have a ``media`` property
 
1472
that returns a list of ``Media`` objects which store paths to the JavaScript
 
1473
files for the forms and/or formsets. If :setting:`DEBUG` is ``True`` it will
 
1474
return the uncompressed versions of the various JavaScript files, including
 
1475
``jquery.js``; if not, it will return the 'minified' versions.
1372
1476
 
1373
1477
.. _jQuery: http://jquery.com
1374
1478
 
1448
1552
- :attr:`~InlineModelAdmin.form`
1449
1553
- :attr:`~ModelAdmin.fieldsets`
1450
1554
- :attr:`~ModelAdmin.fields`
 
1555
- :attr:`~ModelAdmin.formfield_overrides`
1451
1556
- :attr:`~ModelAdmin.exclude`
1452
1557
- :attr:`~ModelAdmin.filter_horizontal`
1453
1558
- :attr:`~ModelAdmin.filter_vertical`
 
1559
- :attr:`~ModelAdmin.ordering`
1454
1560
- :attr:`~ModelAdmin.prepopulated_fields`
 
1561
- :meth:`~ModelAdmin.queryset`
1455
1562
- :attr:`~ModelAdmin.radio_fields`
 
1563
- :attr:`~ModelAdmin.readonly_fields`
1456
1564
- :attr:`~InlineModelAdmin.raw_id_fields`
1457
1565
- :meth:`~ModelAdmin.formfield_for_foreignkey`
1458
1566
- :meth:`~ModelAdmin.formfield_for_manytomany`
1459
1567
 
1460
 
.. versionadded:: 1.2
1461
 
 
1462
 
- :attr:`~ModelAdmin.readonly_fields`
1463
 
- :attr:`~ModelAdmin.formfield_overrides`
1464
 
 
1465
 
.. versionadded:: 1.3
1466
 
 
1467
 
- :attr:`~ModelAdmin.ordering`
1468
 
- :meth:`~ModelAdmin.queryset`
1469
 
 
1470
1568
.. versionadded:: 1.4
1471
1569
 
1472
1570
- :meth:`~ModelAdmin.has_add_permission`
1494
1592
.. attribute:: InlineModelAdmin.form
1495
1593
 
1496
1594
    The value for ``form`` defaults to ``ModelForm``. This is what is passed
1497
 
    through to ``inlineformset_factory`` when creating the formset for this
1498
 
    inline.
 
1595
    through to :func:`~django.forms.models.inlineformset_factory` when
 
1596
    creating the formset for this inline.
1499
1597
 
1500
1598
.. attribute:: InlineModelAdmin.extra
1501
1599
 
1504
1602
    :doc:`formsets documentation </topics/forms/formsets>` for more
1505
1603
    information.
1506
1604
 
1507
 
    .. versionadded:: 1.2
1508
 
 
1509
1605
    For users with JavaScript-enabled browsers, an "Add another" link is
1510
1606
    provided to enable any number of additional inlines to be added in addition
1511
1607
    to those provided as a result of the ``extra`` argument.
1555
1651
    Specifies whether or not inline objects can be deleted in the inline.
1556
1652
    Defaults to ``True``.
1557
1653
 
 
1654
.. method:: InlineModelAdmin.get_formset(self, request, obj=None, **kwargs)
 
1655
 
 
1656
    Returns a ``BaseInlineFormSet`` class for use in admin add/change views.
 
1657
    See the example for :class:`ModelAdmin.get_formsets`.
1558
1658
 
1559
1659
Working with a model with two or more foreign keys to the same parent model
1560
1660
---------------------------------------------------------------------------
1582
1682
Working with many-to-many models
1583
1683
--------------------------------
1584
1684
 
1585
 
.. versionadded:: 1.2
1586
 
 
1587
1685
By default, admin widgets for many-to-many relations will be displayed
1588
1686
on whichever model contains the actual reference to the
1589
1687
:class:`~django.db.models.ManyToManyField`. Depending on your ``ModelAdmin``
1777
1875
necessary nor advisable to replace an entire template. It is almost always
1778
1876
better to override only the section of the template which you need to change.
1779
1877
 
1780
 
To continue the example above, we want to add a new link next to the ``History``
1781
 
tool for the ``Page`` model. After looking at ``change_form.html`` we determine
1782
 
that we only need to override the ``object-tools`` block. Therefore here is our
1783
 
new ``change_form.html`` :
 
1878
To continue the example above, we want to add a new link next to the
 
1879
``History`` tool for the ``Page`` model. After looking at ``change_form.html``
 
1880
we determine that we only need to override the ``object-tools-items`` block.
 
1881
Therefore here is our new ``change_form.html`` :
1784
1882
 
1785
1883
.. code-block:: html+django
1786
1884
 
1787
1885
    {% extends "admin/change_form.html" %}
1788
 
    {% load i18n %}
1789
 
    {% block object-tools %}
1790
 
    {% if change %}{% if not is_popup %}
1791
 
      <ul class="object-tools">
1792
 
        <li><a href="history/" class="historylink">{% trans "History" %}</a></li>
1793
 
        <li><a href="mylink/" class="historylink">My Link</a></li>
 
1886
    {% load i18n admin_urls %}
 
1887
    {% block object-tools-items %}
 
1888
        <li>
 
1889
            <a href="{% url opts|admin_urlname:'history' original.pk|admin_urlquote %}" class="historylink">{% trans "History" %}</a>
 
1890
        </li>
 
1891
        <li>
 
1892
            <a href="mylink/" class="historylink">My Link</a>
 
1893
        </li>
1794
1894
        {% if has_absolute_url %}
1795
 
            <li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">
1796
 
                {% trans "View on site" %}</a>
 
1895
            <li>
 
1896
                <a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">{% trans "View on site" %}</a>
1797
1897
            </li>
1798
1898
        {% endif%}
1799
 
      </ul>
1800
 
    {% endif %}{% endif %}
1801
1899
    {% endblock %}
1802
1900
 
1803
1901
And that's it! If we placed this file in the ``templates/admin/my_app``
1804
 
directory, our link would appear on every model's change form.
 
1902
directory, our link would appear on the change form for all models within
 
1903
my_app.
1805
1904
 
1806
1905
Templates which may be overridden per app or model
1807
1906
--------------------------------------------------
1822
1921
 
1823
1922
.. note::
1824
1923
 
1825
 
    Some of the admin templates, such as ``change_list_request.html`` are used
 
1924
    Some of the admin templates, such as ``change_list_results.html`` are used
1826
1925
    to render custom inclusion tags. These may be overridden, but in such cases
1827
1926
    you are probably better off creating your own version of the tag in
1828
1927
    question and giving it a different name. That way you can use it
1876
1975
 
1877
1976
.. attribute:: AdminSite.login_form
1878
1977
 
1879
 
    .. versionadded:: 1.3
1880
 
 
1881
1978
    Subclass of :class:`~django.contrib.auth.forms.AuthenticationForm` that
1882
1979
    will be used by the admin site login view.
1883
1980
 
1884
1981
.. attribute:: AdminSite.logout_template
1885
1982
 
1886
 
    .. versionadded:: 1.2
1887
 
 
1888
1983
    Path to a custom template that will be used by the admin site logout view.
1889
1984
 
1890
1985
.. attribute:: AdminSite.password_change_template
1891
1986
 
1892
 
    .. versionadded:: 1.2
1893
 
 
1894
1987
    Path to a custom template that will be used by the admin site password
1895
1988
    change view.
1896
1989
 
1897
1990
.. attribute:: AdminSite.password_change_done_template
1898
1991
 
1899
 
    .. versionadded:: 1.2
1900
 
 
1901
1992
    Path to a custom template that will be used by the admin site password
1902
1993
    change done view.
1903
1994
 
1912
2003
``django.contrib.admin.site`` at the URL ``/admin/`` ::
1913
2004
 
1914
2005
    # urls.py
1915
 
    from django.conf.urls import patterns, url, include
 
2006
    from django.conf.urls import patterns, include
1916
2007
    from django.contrib import admin
1917
2008
 
1918
2009
    admin.autodiscover()
1928
2019
``myproject.admin.admin_site`` at the URL ``/myadmin/`` ::
1929
2020
 
1930
2021
    # urls.py
1931
 
    from django.conf.urls import patterns, url, include
 
2022
    from django.conf.urls import patterns, include
1932
2023
    from myproject.admin import admin_site
1933
2024
 
1934
2025
    urlpatterns = patterns('',
1952
2043
respectively::
1953
2044
 
1954
2045
    # urls.py
1955
 
    from django.conf.urls import patterns, url, include
 
2046
    from django.conf.urls import patterns, include
1956
2047
    from myproject.admin import basic_site, advanced_site
1957
2048
 
1958
2049
    urlpatterns = patterns('',
2019
2110
 
2020
2111
The :class:`AdminSite` provides the following named URL patterns:
2021
2112
 
2022
 
======================  ========================  =============
2023
 
Page                    URL name                  Parameters
2024
 
======================  ========================  =============
2025
 
Index                   ``index``
2026
 
Logout                  ``logout``
2027
 
Password change         ``password_change``
2028
 
Password change done    ``password_change_done``
2029
 
i18n javascript         ``jsi18n``
2030
 
Application index page  ``app_list``              ``app_label``
2031
 
======================  ========================  =============
 
2113
=========================  ========================  ==================================
 
2114
Page                       URL name                  Parameters
 
2115
=========================  ========================  ==================================
 
2116
Index                      ``index``
 
2117
Logout                     ``logout``
 
2118
Password change            ``password_change``
 
2119
Password change done       ``password_change_done``
 
2120
i18n javascript            ``jsi18n``
 
2121
Application index page     ``app_list``              ``app_label``
 
2122
Redirect to object's page  ``view_on_site``          ``content_type_id``, ``object_id``
 
2123
=========================  ========================  ==================================
2032
2124
 
2033
2125
Each :class:`ModelAdmin` instance provides an additional set of named URLs:
2034
2126
 
2075
2167
.. code-block:: html+django
2076
2168
 
2077
2169
    {% load admin_urls %}
2078
 
    {% load url from future %}
2079
2170
    <a href="{% url opts|admin_urlname:'add' %}">Add user</a>
2080
2171
    <a href="{% url opts|admin_urlname:'delete' user.pk %}">Delete this user</a>
2081
2172