Django - Admin - 如何覆盖Model Proxy的change_list模板? [英] Django - Admin - How to override change_list template for Model Proxy?

查看:297
本文介绍了Django - Admin - 如何覆盖Model Proxy的change_list模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个简单的Django应用程序。我有一个模型访客。我的目标是在Django管理员中显示两个表。一个与所有的访客,一个只有那些今天。



我通过以下这些说明。但是我不知道如何覆盖只有VisitorExpectedTodayProxy的change_list.html。



我尝试遵循这里的说明,我创建了 Site / templates / admin / VisitorLog / VisitorExpectedTodayProxy / change_list.html ,并在那里进行了修改,但似乎没有将其更改。



Models.py

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

#在管理界面中为不同对象视图制作虚拟模型
class VisitorExpectedTodayProxy(Visitor):
class Meta:
proxy = True
verbose_name =访客
verbose_name_plural =今日访客和常客


解决方案

尝试缩小您的文件夹名称。


注意,管理应用程序将
在查找时小写模型名称
的目录,所以确保你
命名的目录全部小写如果
你要运行你的应用程序在
区分大小写的文件系统。


另外,您是否查看了确保您的模板目录正常工作的清单? TEMPLATE_DIRS 需要包含您的这个模板文件夹,并确保文件系统模板加载器位于 app_directories loader。



最后,您可以通过ModelAdmin属性指向一个模板:
http://docs.djangoproject.com/en/dev/ ref / contrib / admin /#django.contrib.admin.ModelAdmin.change_list_template


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"

解决方案

Try lowercasing your folder names.

Note, that the admin app will lowercase the model name when looking for the directory, so make sure you name the directory in all lowercase if you are going to run your app on a case-sensitive filesystem.

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 the filesystem template loader comes before the app_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

这篇关于Django - Admin - 如何覆盖Model Proxy的change_list模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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