加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

django – 将admin date_hierarchy设置为ForeignKey日期字段

发布时间:2020-12-20 13:37:27 所属栏目:Python 来源:网络整理
导读:当我尝试设置 date_hierarchy = "schedule__date" 时间表是外键. 我收到以下错误. 'TestAdmin.date_hierarchy' refers to field 'schedule__date' that is missing from model 'testing.Test'. 我理解错误.我希望的是这里有一些解决方法允许我从外键日期字段
当我尝试设置

date_hierarchy = "schedule__date"

时间表是外键.

我收到以下错误.

'TestAdmin.date_hierarchy' refers to field 'schedule__date' that is missing from model 'testing.Test'.

我理解错误.我希望的是这里有一些解决方法允许我从外键日期字段中获取date_hierarchy.我已经尝试在Test模型中设置一个方法和propery,它返回日期并将该方法/属性设置为date_hierarchy,但没有运气.

当我已经将它存储在外键中的另一个表中时,必须在schedule_date中为表添加另一列似乎是愚蠢的.

解决方法

不幸的是,目前的django无法做到这一点. date_hierarchy选项显式必须是DateTimeField或DateField:

https://github.com/django/django/blob/stable/1.10.x/django/contrib/admin/checks.py#L837

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读