在 Django 中隐藏日期时间模型字段中的时间?
我正在使用 Thauber 的 可爱的 Django 日程应用,但遇到了一个问题:我不能弄清楚如何排除日期时间字段的时间部分。
我的表单类和蹩脚的排除尝试如下所示:
class LaundryDeliveryForm(EventForm):
start = forms.DateTimeField(widget=forms.SplitDateTimeWidget)
end = forms.DateTimeField(widget=forms.SplitDateTimeWidget, help_text = ("The end time must be later than start time."))
class Meta:
model = LaundryDelivery
exclude = EventForm.Meta.exclude + ('active', 'start.time')
理想情况下,我只想存储日期,或将 start.time 存储为任意时间,例如上午 8 点,但是虽然活动字段被愉快地排除,但时间字段仍然存在打开。
尝试筛选文档,但无法找到我需要的内容。
I'm using Thauber's lovely Django schedule app, but have run into a problem: I can't figure out how to exclude the time portion of the datetime field.
My form class and lame exclusion attempt looks like this:
class LaundryDeliveryForm(EventForm):
start = forms.DateTimeField(widget=forms.SplitDateTimeWidget)
end = forms.DateTimeField(widget=forms.SplitDateTimeWidget, help_text = ("The end time must be later than start time."))
class Meta:
model = LaundryDelivery
exclude = EventForm.Meta.exclude + ('active', 'start.time')
Ideally, I'd like to just store the day, or store the start.time as some arbitrary time like 8 a.m., but while the active field is happily excluded, the time field remains open.
Tried sifting through the documentation but couldn't track what I needed down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
DateInput 小部件
作为当前表单的小部件,或使用forms.DateField()
(它具有默认的DateInput
小部件)。You can use,
DateInput widget
as widget for current form, orforms.DateField()
, which has defaultDateInput
widget.