Django:持续时间
Django : duration in time
目前,我使用 django 1.4.8,我的模型中有以下两个字段:
class Event(models.Model):
...
start = models.DateTimeField(_(u"départ"))
end = models.DateTimeField(_('fin'))
我尝试添加一个字段来指示持续时间
start = models.DateTimeField(_(u"départ"))
time_delay = models.TimeField(_(u"Time_delay"), auto_now_add=True, blank=True, default=datetime.datetime.utcnow)
但我在管理中收到错误
'EventAdmin.fieldsets[0][1]['fields']' refers to field 'time_delay' that is missing from the form
我的管理员:
class EventAdmin(admin.ModelAdmin):
list_display = ('title', 'start', 'contact_time', 'user', 'fin', 'frequency', 'one_file_',)
fieldsets = (
(None, {
'fields': ('title','start', 'contact_time', 'is_cancelled', 'calendar', 'user', 'description', ('frequency', 'fin' ), 'activated', 'one_file',)
}),
)
.....
这是什么问题
您为 time_delay 字段设置了 auto_now_add = True
,因此 django 不会将此字段添加到表单中
class EventAdmin(admin.ModelAdmin):
list_display = ('title', 'start', 'contact_time', 'user', 'fin', 'frequency', 'one_file_',)
fieldsets = (
(None, {
'fields': ('title','start', 'contact_time', 'is_cancelled', 'calendar', 'user', 'description', ('frequency', 'fin' ), 'activated', 'one_file',)
}),
)
readonly_fields = ("time_delay",)
目前,我使用 django 1.4.8,我的模型中有以下两个字段:
class Event(models.Model):
...
start = models.DateTimeField(_(u"départ"))
end = models.DateTimeField(_('fin'))
我尝试添加一个字段来指示持续时间
start = models.DateTimeField(_(u"départ"))
time_delay = models.TimeField(_(u"Time_delay"), auto_now_add=True, blank=True, default=datetime.datetime.utcnow)
但我在管理中收到错误
'EventAdmin.fieldsets[0][1]['fields']' refers to field 'time_delay' that is missing from the form
我的管理员:
class EventAdmin(admin.ModelAdmin):
list_display = ('title', 'start', 'contact_time', 'user', 'fin', 'frequency', 'one_file_',)
fieldsets = (
(None, {
'fields': ('title','start', 'contact_time', 'is_cancelled', 'calendar', 'user', 'description', ('frequency', 'fin' ), 'activated', 'one_file',)
}),
)
.....
这是什么问题
您为 time_delay 字段设置了 auto_now_add = True
,因此 django 不会将此字段添加到表单中
class EventAdmin(admin.ModelAdmin):
list_display = ('title', 'start', 'contact_time', 'user', 'fin', 'frequency', 'one_file_',)
fieldsets = (
(None, {
'fields': ('title','start', 'contact_time', 'is_cancelled', 'calendar', 'user', 'description', ('frequency', 'fin' ), 'activated', 'one_file',)
}),
)
readonly_fields = ("time_delay",)