{"id":75920,"date":"2020-01-20T12:32:59","date_gmt":"2020-01-20T07:02:59","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?p=75920"},"modified":"2024-04-12T14:17:42","modified_gmt":"2024-04-12T08:47:42","slug":"customizing-admin-templates-2","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/","title":{"rendered":"Customizing Admin Templates"},"content":{"rendered":"<p>Out of the box, Django provides a number of tools for customizing the built-in admin templates, which we\u2019ll go over shortly, but for tasks beyond that (e.g., anything requiring custom workflow or granular permissions), you\u2019ll need to read the section titled \u201cCreating Custom Admin Views\u201d later in this chapter. For now, though, let\u2019s look at some quick ways of customizing the appearance (and, to some extent, behavior) of the admin interface. Chapter 6 covers a few of the most common tasks: \u201crebranding\u201d the Django admin interface (for those pointy-haired bosses who hate blue) and providing a custom admin form.<\/p>\n<p>Past that point, the goal usually involves changing some of the templates for a particular item. Each of the admin views \u2014 the change lists, edit forms, delete confirmation pages, and history views \u2014 has an associated template that can be overridden in a number of ways. First, you can override the template globally. The admin view looks for templates using the standard template-loading mechanism, so if you create templates in one of your template directories, Django will load those instead of the default admin templates bundled with Django. These global templates are outlined in Table.<\/p>\n<table>\n<thead>\n<tr>\n<td><strong>View<\/strong><\/td>\n<td><strong>Base Template Name<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Change list<\/td>\n<td>admin\/change_list.html<\/td>\n<\/tr>\n<tr>\n<td>Add\/edit form<\/td>\n<td>admin\/change_form.html<\/td>\n<\/tr>\n<tr>\n<td>Delete confirmation<\/td>\n<td>admin\/delete_confirmation.html<\/td>\n<\/tr>\n<tr>\n<td>Object history<\/td>\n<td>admin\/object_history.html2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Most of the time, however, you\u2019ll want to change the template for just a single object or application (not globally). Thus, each admin view looks for model- and application-specific templates first. Those views look for templates in this order:<\/p>\n<ul>\n<li>admin\/&lt;app_label&gt;\/&lt;object_name&gt;\/&lt;template&gt;.html<\/li>\n<li>admin\/&lt;app_label&gt;\/&lt;template&gt;.html<\/li>\n<li>admin\/&lt;template&gt;.html<\/li>\n<\/ul>\n<p>For example, the add\/edit form view for a Book model in the books application looks for templates in this order:<\/p>\n<ul>\n<li>admin\/books\/book\/change_form.html<\/li>\n<li>admin\/books\/change_form.html<\/li>\n<li>admin\/change_form.html<\/li>\n<\/ul>\n<p><strong>Custom Model Templates<\/strong> &#8211; Most of the time, you\u2019ll want to use the first template to create a model-specific template. This is usually best done by extending the base template and adding information to one of the blocks defined in that template. For example, say we want to add a little bit of help text to the top of that book page. Maybe something like the form shown in Figure.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67708\" src=\"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg\" alt=\"image026\" width=\"496\" height=\"374\"><\/p>\n<p>Figure A customized admin edit form<\/p>\n<p>This is pretty easy to do: simply create a template called admin\/bookstore\/book\/change_form.html and insert this code:<\/p>\n<p>{% extends &#8220;admin\/change_form.html&#8221; %}<br>\n{% block form_top %}<br>\n&lt;p&gt;Insert meaningful help message here&#8230;&lt;\/p&gt;<br>\n{% endblock %}<\/p>\n<p>All these templates define a number of blocks you can override. As with most programs, the best documentation is the code, so we encourage you to look through the admin templates (they\u2019re in<\/p>\n<p>django\/contrib\/admin\/templates\/) for the most up-to-date information.<\/p>\n<p><strong>Custom JavaScript<\/strong> &#8211; A common use for these custom model templates involves adding custom JavaScript to admin pages \u2014 perhaps to implement some special widget or client-side behavior.<\/p>\n<p>Luckily, that couldn\u2019t be easier. Each admin template defines a {% block extrahead %}, which you can use to put extra content into the &lt;head&gt; element. For example, if you want to include jQuery (<a href=\"http:\/\/jquery.com\/\">http:\/\/jquery.com\/<\/a>) in your admin history, it\u2019s as simple as this:<\/p>\n<p>{% extends &#8220;admin\/object_history.html&#8221; %}<br>\n{% block extrahead %}<br>\n&lt;script src=&#8221;http:\/\/media.example.com\/javascript\/jquery.js&#8221; type=&#8221;text\/javascript&#8221;&gt;&lt;\/script&gt;<br>\n&lt;script type=&#8221;text\/javascript&#8221;&gt;<br>\n\/\/ code to actually use jQuery here&#8230;<br>\n&lt;\/script&gt;<br>\n{% endblock %}<\/p>\n<p><strong>Note<\/strong> &#8211; We\u2019re not sure why you\u2019d need jQuery on the object history page, but, of course, this example applies to any of the admin templates.<\/p>\n<p>You can use this technique to include any sort of extra JavaScript widgets you might need.<\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/certified-django-developer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Back to Tutorial<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Out of the box, Django provides a number of tools for customizing the built-in admin templates, which we\u2019ll go over shortly, but for tasks beyond that (e.g., anything requiring custom workflow or granular permissions), you\u2019ll need to read the section titled \u201cCreating Custom Admin Views\u201d later in this chapter. For now, though, let\u2019s look at&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[8655],"tags":[2663],"class_list":["post-75920","page","type-page","status-publish","hentry","category-django-web-development","tag-customizing-admin-templates"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Customizing Admin Templates - Tutorial<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Customizing Admin Templates - Tutorial\" \/>\n<meta property=\"og:description\" content=\"Out of the box, Django provides a number of tools for customizing the built-in admin templates, which we\u2019ll go over shortly, but for tasks beyond that (e.g., anything requiring custom workflow or granular permissions), you\u2019ll need to read the section titled \u201cCreating Custom Admin Views\u201d later in this chapter. For now, though, let\u2019s look at...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:47:42+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/\",\"name\":\"Customizing Admin Templates - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg\",\"datePublished\":\"2020-01-20T07:02:59+00:00\",\"dateModified\":\"2024-04-12T08:47:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#primaryimage\",\"url\":\"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg\",\"contentUrl\":\"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Customizing Admin Templates\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Customizing Admin Templates - Tutorial","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/","og_locale":"en_US","og_type":"article","og_title":"Customizing Admin Templates - Tutorial","og_description":"Out of the box, Django provides a number of tools for customizing the built-in admin templates, which we\u2019ll go over shortly, but for tasks beyond that (e.g., anything requiring custom workflow or granular permissions), you\u2019ll need to read the section titled \u201cCreating Custom Admin Views\u201d later in this chapter. For now, though, let\u2019s look at...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:47:42+00:00","og_image":[{"url":"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/","name":"Customizing Admin Templates - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#primaryimage"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#primaryimage"},"thumbnailUrl":"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg","datePublished":"2020-01-20T07:02:59+00:00","dateModified":"2024-04-12T08:47:42+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#primaryimage","url":"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg","contentUrl":"http:\/\/www.vskills.in\/lms\/wp-content\/uploads\/2016\/07\/image026-2.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/customizing-admin-templates-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Customizing Admin Templates"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=75920"}],"version-history":[{"count":4,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75920\/revisions"}],"predecessor-version":[{"id":83438,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/75920\/revisions\/83438"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=75920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=75920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=75920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}