Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Admin: using different templates for two admin site

I've a Django project with two different admin-site (as described in documentation )

I would like to have different custom template for each of them. I know how to override custom template, by putting html files in myproject/templates/admin/ directory. However, both admin-site use those templates !

I don't understand how to specify another set of custom templates.

Ideally, I would like having:

# For first admin site
myproject/templates/admin-a/
   base.html
   base_site.html

and:

# For second admin site
myproject/templates/admin-b/
   base.html
   base_site.html
like image 693
Stéphane Avatar asked Mar 24 '11 14:03

Stéphane


1 Answers

first option will be to have two ModelAdmin classes, one derived from second one, with some additional parameters defining templates, here is part of the admin code:

# Custom templates (designed to be over-ridden in subclasses)
add_form_template = None
change_form_template = None
change_list_template = None
delete_confirmation_template = None
delete_selected_confirmation_template = None
object_history_template = None

above variables can be set in your admin class.

second way is to pass a base template name into the template, and then use this (variable) as a parameter to the extends template tag. Documentation here.

third option wil be to have a two instances of code running, but with two configs with different setting variable TEMPLATE_DIRS, first one e.g.:

TEMPLATE_DIRS = ('templates-a',)

second

TEMPLATE_DIRS = ('template-b', 'template-a')

Having both template dirs here gives you an fallback option, so you will define only those templates which are different.

Third option is easiest to implement (no change to the code) but it requires 2 separated instances working at the same time (more system resources consumed).

like image 182
Jerzyk Avatar answered Oct 06 '22 18:10

Jerzyk