Django: how to change the choices of AdminTimeWidget

后端 未结 6 1770
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 12:29

The AdminTimeWidget rendered in admin for a DateTimeField displays an icon of a clock and when you click you have the choice between: \"Now Midnigh

6条回答
  •  既然无缘
    2020-12-08 12:33

    I went with a much simpler approach and it worked for me. I simply added choices to my model using the following code:

    class Class(Model): program = ForeignKey('Program') time_of_the_day = TimeField(choices=( (datetime.datetime.strptime('7:00 am', "%I:%M %p").time(), '7:00 am'), (datetime.datetime.strptime('8:00 am', "%I:%M %p").time(), '8:00 am'), (datetime.datetime.strptime('9:00 am', "%I:%M %p").time(), '9:00 am'), (datetime.datetime.strptime('6:00 pm', "%I:%M %p").time(), '6:00 pm'), (datetime.datetime.strptime('7:00 pm', "%I:%M %p").time(), '7:00 pm'), (datetime.datetime.strptime('8:00 pm', "%I:%M %p").time(), '8:00 pm'), (datetime.datetime.strptime('9:00 pm', "%I:%M %p").time(), '9:00 pm'),
    ))

    Hope this helps

提交回复
热议问题