Django - 管理员 - 如何覆盖模型代理的change_list模板?
我做了一个简单的 Django 应用程序。我有一个模型“访客”。我的目标是在 Django 管理中显示两个表。一间包含所有访客,另一间只包含今天的访客。
我按照 这些说明,使用下面的代码完成了所有工作。但我不确定如何仅覆盖 VisitorExpectedTodayProxy 的change_list.html。
我尝试按照此处的说明进行操作创建了 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"
I made a simple Django app. I have one model "Visitor". My goal is to have two tables appear in the Django admin. One with all of the visitors and one with only those for today.
I got everything working with the code below by following these instructions. But I'm not sure how to override just the change_list.html for just VisitorExpectedTodayProxy.
I tried following the instructions here and I created Site/templates/admin/VisitorLog/VisitorExpectedTodayProxy/change_list.html
and made my changes there, but it doesn't seem to be picking it up.
Models.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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了小写你的路径之外,
你的change_list.html的内容应该扩展默认的admin/change_list:
你可以通过查看django源代码中的各种块模板来自定义此页面的不同部分:
On top of lowercasing your paths to look like:
The content of your change_list.html should extend the default admin/change_list:
You can customise the different section of this page by looking at the various block templates in the django source code:
尝试小写文件夹名称。
另外,您是否已检查过确保模板目录正常工作的清单?
TEMPLATE_DIRS
需要包含您的模板文件夹,并确保filesystem
模板加载器位于app_directories
加载器之前。最后,您可以通过 ModelAdmin 属性指向模板:
http://docs.djangoproject。 com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_list_template
Try lowercasing your folder names.
Also, have you gone through the checklist of making sure your templates directory is working at all?
TEMPLATE_DIRS
needs to contain this templates folder of yours, and make sure thefilesystem
template loader comes before theapp_directories
loader.Finally, you can point to a template via a ModelAdmin attribute:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.change_list_template