Ticket #10415: 10415-custom_admin_templates_and_views_docs.diff

File 10415-custom_admin_templates_and_views_docs.diff, 6.4 KB (added by Ramiro Morales, 15 years ago)

Patch for this ticket, applies cleanly to truk as of r11079

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

    diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
    a b  
    667667changelist displays actions at the top of the page (``actions_on_top = True;
    668668actions_on_bottom = False``).
    669669
     670.. attribute:: ModelAdmin.change_list_template
     671
     672.. versionadded:: 1.0
     673
     674Path to a custom template that will be used by the model objects "change list"
     675view. The template file searching order and precedence rules and modular
     676extension strategy recommendations outlined in the `Overriding Admin Templates`_
     677section apply here.
     678
     679If you don't specify it, a default template shipped with Django that provides
     680the standard appearance is used.
     681
     682.. attribute:: ModelAdmin.change_form_template
     683
     684.. versionadded:: 1.0
     685
     686Path to a custom template that will be used by both the model object creation
     687and change views. The template file searching order and precedence rules and
     688modular extension strategy recommendations outlined in the `Overriding Admin
     689Templates`_ section apply here.
     690
     691If you don't specify it, a default template shipped with Django that provides
     692the standard appearance is used.
     693
     694.. attribute:: ModelAdmin.object_history_template
     695
     696.. versionadded:: 1.0
     697
     698Path to a custom template that will be used by the model object change history
     699display view. The template file searching order and precedence rules and modular
     700extension strategy recommendations outlined in the `Overriding Admin Templates`_
     701section apply here.
     702
     703If you don't specify it, a default template shipped with Django that provides
     704the standard appearance is used.
     705
     706.. attribute:: ModelAdmin.delete_confirmation_template
     707
     708.. versionadded:: 1.0
     709
     710Path to a custom template that will be used by the view responsible of showing
     711the confirmation page when the user decides to delete one or more model objects.
     712The template file searching order and precedence rules and modular extension
     713strategy recommendations outlined in the `Overriding Admin Templates`_ section
     714apply here.
     715
     716If you don't specify it, a default template shipped with Django that provides
     717the standard appearance is used.
     718
    670719``ModelAdmin`` methods
    671720----------------------
    672721
     
    762811This uses the ``HttpRequest`` instance to filter the ``Car`` foreign key field
    763812to only the cars owned by the ``User`` instance.
    764813
     814Other methods
     815~~~~~~~~~~~~~
     816
     817.. method:: ModelAdmin.add_view(self, request, form_url='', extra_context=None)
     818
     819Django view for the model instance addition page. See note below.
     820
     821.. method:: ModelAdmin.change_view(self, request, object_id, extra_context=None)
     822
     823Django view for the model instance edition page. See note below.
     824
     825.. method:: ModelAdmin.changelist_view(self, request, extra_context=None)
     826
     827Django view for the model instances change list/actions page. See note below.
     828
     829.. method:: ModelAdmin.delete_view(self, request, object_id, extra_context=None)
     830
     831Django view for the model instance(s) deletion confirmation page. See note below.
     832
     833.. method:: ModelAdmin.history_view(self, request, object_id, extra_context=None)
     834
     835Django view for the page that shows the modification history for a given model
     836instance.
     837
     838Unlike the hook-type ``ModelAdmin`` methods detailed in the previous section,
     839these five methods are in reality designed to be invoked as Django views from
     840the admin application URL dispatching handler to render the pages that deal
     841with model instancies CRUD operations. Because of that they implement the
     842complex logic specific to the generic nature of the admin app and there aren't
     843many possibilities to customize their behavior other than replace their
     844implementation.
     845
     846.. versionadded:: 1.0
     847
     848Nonetheless, you still can customize the presentation of their respective pages
     849(possibly transforming them completely) if needed: For this, you override the
     850method in your ``ModelAdmin`` subclass to augment the context provided to the
     851template layer using its ``extra_context`` parameter and at the same time
     852override the associated template used by the admin with the respective
     853``*_template`` option described in the `ModelAdmin options`_ section. An
     854example::
     855
     856    class MyModelAdmin(admin.ModelAdmin):
     857
     858        # A template for a very customized change view:
     859        change_form_template = 'admin/myapp/extras/openstreetmap_change_form.html'
     860
     861        def get_osm_info(self):
     862            # ...
     863
     864        def change_view(self, request, form_url='', extra_context=None):
     865            my_context = {
     866                'osm_data': self.get_osm_info(),
     867            }
     868            return super(MyModelAdmin, self).change_view(request,
     869                extra_context=my_context))
     870
    765871``ModelAdmin`` media definitions
    766872--------------------------------
    767873
     
    11061212Templates which may be overridden per app or model
    11071213--------------------------------------------------
    11081214
    1109 Not every template in ``contrib\admin\templates\admin`` may be overridden per
     1215Not every template in ``contrib/admin/templates/admin`` may be overridden per
    11101216app or per model. The following can:
    11111217
    11121218    * ``app_index.html``
     
    11311237------------------------
    11321238
    11331239If you wish to change the index or login templates, you are better off creating
    1134 your own ``AdminSite`` instance (see below), and changing the ``index_template``
    1135 or ``login_template`` properties.
     1240your own ``AdminSite`` instance (see below), and changing the :attr:`AdminSite.index_template`
     1241or :attr:`AdminSite.login_template` properties.
    11361242
    11371243``AdminSite`` objects
    11381244=====================
     
    11511257Python class), and register your models and ``ModelAdmin`` subclasses
    11521258with it instead of using the default.
    11531259
     1260``AdminSite`` attributes
     1261------------------------
     1262
     1263.. attribute:: AdminSite.index_template
     1264
     1265.. versionadded:: 1.0
     1266
     1267Path to a custom template that will be used by the admin site main index view.
     1268The template file searching order and precedence rules and modular extension
     1269strategy recommendations outlined in the `Overriding Admin Templates`_ section
     1270apply here.
     1271
     1272.. attribute:: AdminSite.login_template
     1273
     1274.. versionadded:: 1.0
     1275
     1276Path to a custom template that will be used by the admin site login view.
     1277The template file searching order and precedence rules and modular extension
     1278strategy recommendations outlined in the `Overriding Admin Templates`_ section
     1279apply here.
     1280
    11541281Hooking ``AdminSite`` instances into your URLconf
    11551282-------------------------------------------------
    11561283
Back to Top