DateTimeField 不显示在管理系统中 [英] DateTimeField doesn't show in admin system

查看:26
本文介绍了DateTimeField 不显示在管理系统中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期"字段怎么没有出现在管理系统中?

How come my "date" field doesn't come up in the admin system?

在我的 admin.py 文件中

In my admin.py file i have

from django.contrib import admin
from glasses.players.models import *
admin.site.register(Rating)

评级模型有一个名为日期"的字段,看起来像这样

and the Rating model has a field called "date" which looks like this

date = models.DateTimeField(editable=True, auto_now_add=True)

但是在管理系统中,该字段不显示,即使 editable 设置为 True.

However within the admin system, the field doesn't show, even though editable is set to True.

有人知道吗?

推荐答案

我相信原因在于 auto_now_add 字段.

I believe to reason lies with the auto_now_add field.

来自这个答案:

具有 auto_now 属性的任何字段set 也将继承 editable=False因此不会出现在管理面板.

Any field with the auto_now attribute set will also inherit editable=False and therefore will not show up in the admin panel.

文档中也提到过:

按照目前的实施,设置auto_now 或 auto_now_add 到 True 将导致该字段具有可编辑=假和空白=真设置.

As currently implemented, setting auto_now or auto_now_add to True will cause the field to have editable=False and blank=True set.

这是有道理的,因为如果在保存对象时该字段将被当前日期时间覆盖,则没有理由让该字段可编辑.

This does make sense, since there is no reason to have the field editable if it's going to be overwritten with the current datetime when the object is saved.

这篇关于DateTimeField 不显示在管理系统中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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