1

我在我的模型中更新 TimeField 时遇到问题 - 当我想使用表单/表单集编辑对象时,我网站上的输入字段总是减少微秒。

我做了前任。带有 TimeField 的类:

class Participant(models.Model):
    surname = models.CharField(max_length = 256)
    name = models.CharField(max_length = 256)
    birth = models.DateField(blank = True, null = True)
    entry_time = models.TimeField(blank = True, null = True)
                      ...

然后我做了一个表格:

class ParticipantForm(forms.ModelForm):
       ....
       entry_time = forms.TimeField(initial="HH:MM:SS.00", 
       required = False, 
       widget=forms.TimeInput(format=('%H:%M:%S.%f')))
       ....

当我通过表单添加新参与者时,一切正常。entry_time 的值以正确的格式(小时:分钟:秒.微秒)保存在我的数据库中。但是,当我想使用此表单或表单集更新我的参与者时会出现问题。加载到表单的数据始终没有微秒(小时:分钟:秒)。

我网站上的输出看起来像这样(照片)

first generated by: {{ formset.time_score }} 
second: <input type="text" value="{{ participant.time_score|time:"H:i:s:u" }}">

如果我使用表单或表单集,这并不重要 - 结果是一样的。

希望各位大神帮忙,我想不通。

4

0 回答 0