DurationField with default value

387 views
Skip to first unread message

Mathijs Jonker

unread,
Apr 17, 2015, 1:06:09 PM4/17/15
to django...@googlegroups.com
Hi,

I'm trying to figure out how to use a default value with a duration field.

When I use time_passed = models.DurationField(default=0):

  * Migrations work
  * Form defaults don't work 'int' object has no attribute
    'total_seconds'

When I use time_passed = models.DurationField(default=timedelta()):

  * Migrations don't work ValueError: Cannot serialize:
    datetime.timedelta(0)
  * model default works

So what is the right way to use a default value on duration field or is 
this a bug?

(stackoverflow question: http://stackoverflow.com/questions/29699857/django-durationfield-default-value)
With kind regards, mjonker

Tim Graham

unread,
Apr 17, 2015, 4:26:39 PM4/17/15
to django...@googlegroups.com
It's a bug that Django cannot serialize timedelta objects in migrations. It will be fixed in 1.8.1 -- see https://code.djangoproject.com/ticket/24566.
Reply all
Reply to author
Forward
0 new messages