Ticket #10415: 10415-custom_admin_templates_and_views_docs-1.0.x.diff

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

Same patch as above but for the 1.0.x branch. Applies cleanly to truk as of r11079

  • docs/ref/contrib/admin.txt

    diff --git a/docs/ref/contrib/admin.txt b/docs/ref/contrib/admin.txt
    a b  
    583583    Performs a full-text match. This is like the default search method but uses
    584584    an index. Currently this is only available for MySQL.
    585585
     586.. attribute:: ModelAdmin.change_list_template
     587
     588.. versionadded:: 1.0
     589
     590Path to a custom template that will be used by the model objects "change list"
     591view. The template file searching order and precedence rules and modular
     592extension strategy recommendations outlined in the `Overriding Admin Templates`_
     593section apply here.
     594
     595If you don't specify it, a default template shipped with Django that provides
     596the standard appearance is used.
     597
     598.. attribute:: ModelAdmin.change_form_template
     599
     600.. versionadded:: 1.0
     601
     602Path to a custom template that will be used by both the model object creation
     603and change views. The template file searching order and precedence rules and
     604modular extension strategy recommendations outlined in the `Overriding Admin
     605Templates`_ section apply here.
     606
     607If you don't specify it, a default template shipped with Django that provides
     608the standard appearance is used.
     609
     610.. attribute:: ModelAdmin.object_history_template
     611
     612.. versionadded:: 1.0
     613
     614Path to a custom template that will be used by the model object change history
     615display view. The template file searching order and precedence rules and modular
     616extension strategy recommendations outlined in the `Overriding Admin Templates`_
     617section apply here.
     618
     619If you don't specify it, a default template shipped with Django that provides
     620the standard appearance is used.
     621
     622.. attribute:: ModelAdmin.delete_confirmation_template
     623
     624.. versionadded:: 1.0
     625
     626Path to a custom template that will be used by the view responsible of showing
     627the confirmation page when the user decides to delete one or more model objects.
     628The template file searching order and precedence rules and modular extension
     629strategy recommendations outlined in the `Overriding Admin Templates`_ section
     630apply here.
     631
     632If you don't specify it, a default template shipped with Django that provides
     633the standard appearance is used.
     634
    586635``ModelAdmin`` methods
    587636----------------------
    588637
     
    616665                instance.save()
    617666            formset.save_m2m()
    618667
     668Other methods
     669~~~~~~~~~~~~~
     670
     671.. method:: ModelAdmin.add_view(self, request, form_url='', extra_context=None)
     672
     673Django view for the model instance addition page. See note below.
     674
     675.. method:: ModelAdmin.change_view(self, request, object_id, extra_context=None)
     676
     677Django view for the model instance edition page. See note below.
     678
     679.. method:: ModelAdmin.changelist_view(self, request, extra_context=None)
     680
     681Django view for the model instances change list/actions page. See note below.
     682
     683.. method:: ModelAdmin.delete_view(self, request, object_id, extra_context=None)
     684
     685Django view for the model instance(s) deletion confirmation page. See note below.
     686
     687.. method:: ModelAdmin.history_view(self, request, object_id, extra_context=None)
     688
     689Django view for the page that shows the modification history for a given model
     690instance.
     691
     692Unlike the hook-type ``ModelAdmin`` methods detailed in the previous section,
     693these five methods are in reality designed to be invoked as Django views from
     694the admin application URL dispatching handler to render the pages that deal
     695with model instancies CRUD operations. Because of that they implement the
     696complex logic specific to the generic nature of the admin app and there aren't
     697many possibilities to customize their behavior other than replace their
     698implementation.
     699
     700.. versionadded:: 1.0
     701
     702Nonetheless, you still can customize the presentation of their respective pages
     703(possibly transforming them completely) if needed: For this, you override the
     704method in your ``ModelAdmin`` subclass to augment the context provided to the
     705template layer using its ``extra_context`` parameter and at the same time
     706override the associated template used by the admin with the respective
     707``*_template`` option described in the `ModelAdmin options`_ section. An
     708example::
     709
     710    class MyModelAdmin(admin.ModelAdmin):
     711
     712        # A template for a very customized change view:
     713        change_form_template = 'admin/myapp/extras/openstreetmap_change_form.html'
     714
     715        def get_osm_info(self):
     716            # ...
     717
     718        def change_view(self, request, form_url='', extra_context=None):
     719            my_context = {
     720                'osm_data': self.get_osm_info(),
     721            }
     722            return super(MyModelAdmin, self).change_view(request,
     723                extra_context=my_context)
     724
    619725``ModelAdmin`` media definitions
    620726--------------------------------
    621727
     
    9601066Templates which may be overridden per app or model
    9611067--------------------------------------------------
    9621068
    963 Not every template in ``contrib\admin\templates\admin`` may be overridden per
     1069Not every template in ``contrib/admin/templates/admin`` may be overridden per
    9641070app or per model. The following can:
    9651071
    9661072    * ``change_form.html``
     
    9841090------------------------
    9851091
    9861092If you wish to change the index or login templates, you are better off creating
    987 your own ``AdminSite`` instance (see below), and changing the ``index_template``
    988 or ``login_template`` properties.
     1093your own ``AdminSite`` instance (see below), and changing the :attr:`AdminSite.index_template`
     1094or :attr:`AdminSite.login_template` properties.
    9891095
    9901096``AdminSite`` objects
    9911097=====================
     
    10031109with it instead of using the default.
    10041110
    10051111
     1112``AdminSite`` attributes
     1113------------------------
     1114
     1115.. attribute:: AdminSite.index_template
     1116
     1117.. versionadded:: 1.0
     1118
     1119Path to a custom template that will be used by the admin site main index view.
     1120The template file searching order and precedence rules and modular extension
     1121strategy recommendations outlined in the `Overriding Admin Templates`_ section
     1122apply here.
     1123
     1124.. attribute:: AdminSite.login_template
     1125
     1126.. versionadded:: 1.0
     1127
     1128Path to a custom template that will be used by the admin site login view.
     1129The template file searching order and precedence rules and modular extension
     1130strategy recommendations outlined in the `Overriding Admin Templates`_ section
     1131apply here.
     1132
    10061133Hooking ``AdminSite`` instances into your URLconf
    10071134-------------------------------------------------
    10081135
Back to Top