Is it possible to have a DateField without the year? Or will I have to use a CharField? I am using the admin to edit the models.
问问题
4557 次
3 回答
2
您需要确定是否可以使用模型(和数据库)上的常规日期对象,并且只自定义表单小部件,或者您是否希望数据存储具有特定数据。
如果您只想让表单显示日期和月份,则需要编写一个自定义小部件并将其连接到 ModelAdmin 类中的表单。Django 的文档对编写自定义字段和自定义小部件有很好的介绍
在这两种情况下,将现有模型/小部件子类化并更改您想要的行为要容易得多。
于 2010-06-18T15:59:13.513 回答
1
A DateField
is a whole date. If you only care about the month and day then use __month
and __day
when querying.
于 2010-06-18T05:53:01.317 回答
1
这对我有用:
data_sorted = sorted(My_Model.objects.all(), key=lambda e: e.myDataField.strftime("%m-%d"))
于 2013-10-03T19:38:04.033 回答