仅对某些模型覆盖Django admin change_list_results.html [英] Overriding the Django admin change_list_results.html only for some models

查看:193
本文介绍了仅对某些模型覆盖Django admin change_list_results.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想为我的一个模型覆盖template / admin / change_list_results.html和templates / admin / change_list.html模板。
如何告诉管理员将该模型与应用程序中的所有其他模型区分开来,并呈现与默认模型不同的更改模板?
如果我只是编辑change_list_results.html,那么管理员视图中的所有模型都将反映我的更改。

解决方案

您可以在此处中查看文档。。 p>

简短的版本是您需要在 admin / your-app-name / your-model-name / change_list.html 在您的模板路径中。它可以在应用程序中,也可以在您的根模板目录中。



一个陷阱是Django需要先找到它,然后才能找到默认的 admin / change_list.html在 django.contrib.admin 中。如果在应用程序中,请确保该应用程序在 INSTALLED_APPS 之前 django.contrib.admin 中列出$ c>。我通常只是将管理模板替代项放到我的根模板文件夹中,因为它是在应用程序之前加载的。


I want to override the templates/admin/change_list_results.html and templates/admin/change_list.html templates for just one of my models. How do I tell the admin to differentiate this model from all the others in my app and render a different change template than the default? If I just edit change_list_results.html then all the models in the admin views will reflect my changes.

解决方案

You can, see documentation here.

The short version is that you need a custom template at admin/your-app-name/your-model-name/change_list.html in your template path. It can be in an an app or in your root template directory.

The one catch is that Django needs to find it before it finds the default "admin/change_list.html" in django.contrib.admin. If it's in an app, make sure that app is listed before django.contrib.admin in INSTALLED_APPS. I usually just put admin template overrides in my root templates folder, since that gets loaded before apps.

这篇关于仅对某些模型覆盖Django admin change_list_results.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆