to override a django admin template for a particular model:
- 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.
- 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.
- Save the new file into your project’s templates folder, using the following directory structure:
The steps are a bit different for an Inline model.
- Do steps 1 & 2 above.
- 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.
- 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)