Django TimeField Model without seconds

前端 未结 7 2165
青春惊慌失措
青春惊慌失措 2021-02-08 12:48

Greetings, I am trying to implement a TimeField model which only consists of HH:MM (ie 16:46) format, I know it is possible to format a regular Python time object but I am lost

7条回答
  •  自闭症患者
    2021-02-08 13:19

    You can at least modify the output in the __str__ method on the model by using datetime.time.isoformat(timespec='minutes'), like this:

    def __str__(self):
        return self.value.isoformat(timespec='minutes')
    

    Now the value is showing as HH:MM in admin pages.

提交回复
热议问题