What's the right way to use Django's DurationField
?
When I use time_passed = models.DurationField(default=0)
:
'int' object has no attribute 'total_seconds'
)When I use time_passed = models.DurationField(default=timedelta())
:
ValueError: Cannot serialize: datetime.timedelta(0)
)So what is the right way to use a default value on duration field or a workaround for this issue?
The default should be a timedelta. This is a bug in Django and is set to be fixed in the 1.8.1 release.
See: https://code.djangoproject.com/ticket/24566
So using default should be:
time_passed = models.DurationField(default=timedelta())