将admin date_hierarchy设置为ForeignKey日期字段 [英] Set admin date_hierarchy to a ForeignKey date field
问题描述
当我尝试设置
date_hierarchy = "schedule__date"
计划是外键的地方。
我收到以下错误。
'TestAdmin.date_hierarchy' refers to field 'schedule__date' that is missing from model 'testing.Test'.
我了解此错误。我希望这里有一种解决方法,可以让我从外键日期字段获得date_hierarchy。我尝试在Test模型中设置一个返回日期的方法和属性,并将该方法/属性设置为date_hierarchy,但是没有运气。
I understand the error. What I'm hoping for is that there is some sort of workaround here to allow me to have date_hierarchy from a foreign key date field. I have tried setting a method and propery within the Test model that returns the date and setting that method/property as the date_hierarchy, but no luck.
当我已经通过外键将其存储在另一个表中时,不得不在schedule_date的表中添加另一列似乎很愚蠢。
It seems foolish to have to add another column to my table for the schedule__date when I already have it stored in another table from the foreign key.
推荐答案
不幸的是,当前的django无法做到这一点。明确要求 date_hierarchy
选项是 DateTimeField
或 DateField
:
Unforturnately, this isn't possible with the current django. The date_hierarchy
option is explicitly required to be a DateTimeField
or DateField
:
https://github.com/django/django/blob/stable/1.10.x/django/contrib/admin/checks.py#L837
这篇关于将admin date_hierarchy设置为ForeignKey日期字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!