Difficulty using the new DurationField in Django 1.8
I am having problems with Django new DurationField for models.
I want the user to be able to choose whether the duration of the event on my web server is 1 day, 3 days, or 5 days, with a default of 3 days.
At the beginning of my model, I declare a choice:
SHORT = datetime.timedelta(days=1) MEDIUM = datetime.timedelta(days=3) LONG = datetime.timedelta(days=5) DURATION_CHOICES = ((SHORT, '1 day'),(MEDIUM, '3 days'), (LONG, '5 days'),)
Then below I declare a DurationField:
duration = models.DurationField(choices = DURATION_CHOICES, default = MEDIUM)
I created a model model for the model and displayed it on the appropriate template. In the “3 days” form, the selected choice was in the drop-down list, as well as “1 day” and “5 days”. However, when I submit the form, I get a form validation error "Select the correct option. 3 days, 0:00:00 is not one of the available options."
However, when I remove the selection from the DurationField and leave it by default:
duration = models.DurationField(default = MEDIUM)
I can send without any problems. What am I doing wrong here?