python - Django - 管理员 - 如何覆盖模型代理的 change_list 模板?

标签 python django django-admin django-templates

我制作了一个简单的 Django 应用程序。我有一个模型“访客”。我的目标是让两个表出现在 Django 管理中。一个是所有访客,一个是今天的访客。

通过遵循 these instructions,我得到了使用下面代码的所有功能.但我不确定如何仅覆盖 VisitorExpectedTodayProxy 的 change_list.html。

我尝试关注 instructions here并且我创建了 Site/templates/admin/VisitorLog/VisitorExpectedTodayProxy/change_list.html 并在那里进行了更改,但它似乎没有接收到它。

模型.py

class Visitor(models.Model):
    visit_datetime = models.DateTimeField(null=True)
    visitor_name = models.CharField(max_length=500)

#Make dummy models for different object views in admin interface
class VisitorExpectedTodayProxy(Visitor):
    class Meta:
        proxy=True
        verbose_name = "Visitor"
        verbose_name_plural = "Today's Visitors and Regular Visitors"

最佳答案

除了小写你的路径看起来像:

templates/admin/visitorlog/visitorexpectedtodayproxy/change_list.html

您的 change_list.html 的内容应该扩展默认的 admin/change_list:

{% extends "admin/change_list.html" %}

您可以通过查看 django 源代码中的各种 block 模板来自定义此页面的不同部分:

django/contrib/admin/templates/admin/change_list.html

关于python - Django - 管理员 - 如何覆盖模型代理的 change_list 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5488159/

相关文章:

python - PyGame 负色/表面

javascript - 如何从 Django 中的 html 或 js 访问环境变量

python - 如何在Python中检查套接字是否在这一端关闭

python - Django Web 应用程序的多用户高效时间序列存储

python - 加权页面排名图表示

django - Heroku。 Django转储数据

django - 关于如何在 django 中编写自定义表单字段的教程?

javascript - Django 管理员 : including some data from the database in a change_form

python - django-admin-sortable 不保存现有对象的顺序

python - 使用 OneToOneField 扩展 Django Admin UserCreationForm