Django Journal: Override a Django Admin Template, Inline or Otherwise

to override a django admin template for a particular model:

  1. Locate the original template in “your_python_installation/site-packages/django/contrib/admin/templates.” For this tut we’ll assume you’re trying to override change_list.html.
  2. Copy what you need from that template and paste it into a blank .html file. Usually your best bet is to copy all of it and then whittle it down later.
  3. Save the new file into your project’s templates folder, using the following directory structure:
    templates/admin/your_app_name/your_model/change_list.html

The steps are a bit different for an Inline model.

  1. Do steps 1 & 2 above.
  2. Save the file in your templates folder. It doesn’t really matter where it goes, but for consistency’s sake you can place it using a dir structure similar to the above. Take note of the path.
  3. in the Inline class you’re targeting, set template = the path where you placed the file. so your Inline class may look like the following:
    class ImageInline(admin.StackedInline):
        model = ProductImage
        extra = 1
        template = "admin/products/productimage/edit_inline/stacked.html"
    


Robert Martin’s Clean Code series WILL make you the best programmer you can possibly be:
The Clean Coder: A Code of Conduct for Professional Programmers (Robert C. Martin Series)

Get Adobe Flash player