I also just realised that it's common to use an integer as the first element of a choice pair. Maybe the only restriction is that the datatype you use in the choice pair match the model field you're eventually saving it back to?
On Sep 13, 3:20 pm, josephi <jose...@dircsa.org.au> wrote: > Hello > > I have a model Booking with a TimeField start_time on it. I want to > ensure that times entered into this field are whole hours only. > > I've set up a ModelAdmin object to use this model in the admin > interface. On the ModelAdmin I've used a custom ModelForm where I > override the default field for start_time and use a ChoiceField with > choices set to something like this ((time(9), '9 am'), (time(10), '10 > am'), ...). > > This seems to work perfectly well, with the correct time values being > saved to the database. The only real reason I'm asking this question > is that I couldn't find any examples of anything other than a string > being used as the first element of a choice pair. In my case I've used > a datetime.time. Can anyone think of any way that this might cause > problems or stop working in a future version of django? Is it intended > that you can use arbitrary objects in choices, or is this only working > accidentally? > > Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.