Задать вопрос

Тел: +7 965 3737 888





Timedelta Database Field

<p>This subclass of django.models.Field stores a python datetime.timedelta object
as an integer column in the database.</p>
<p>It includes a TimedeltaFormField for editing it through djangos admin interface.</p>
<p>Feedback welcome.</p>
<p>2011-04-20: TimedeltaField can now be (de)serialized. Tested with JSON.</p>
<p>2009-11-23: _has_changed() added. Before form.changed_data contained timedelta FormFields,
even if nothing changed.</p>

Вопрос полезен? Да0/Нет0

Ответы (7):

Ответ полезен? Да0/Нет0

Where do I find djangotools? There is a repo on github but it does not contain a module called southutils.

Ответ полезен? Да0/Нет0

This is really handy, thanks!

Ответ полезен? Да0/Нет0

I got this message from Google Group.

And thank you for your snippet I will try it.

Ответ полезен? Да0/Нет0

hi, in admin, assert in to_python throws exception. my quickfix follows:

def to_python(self, value):
    if (value is None) or isinstance(value, datetime.timedelta):
        return value
    if value == '':
        value = 0
    assert isinstance(value, int), (value, type(value))
    return datetime.timedelta(seconds=value)

Serializing model with TimeDelta field then loading fixture, also fails to assert(TimeField is represented as string, i.e. '2:03:00')

Ответ полезен? Да0/Нет0

I just uploaded a new version. I think the reported bug was fixed.

Ответ полезен? Да0/Нет0

Hi jonson, I couldn't find your email address.

I can't reproduce your problem. Please send me the traceback. Please send the HTML-Debug Traceback to hv@tbz-pariv.de.

Ответ полезен? Да0/Нет0

Hi there, great Field! Only one improvement, timedelta filled with zeros causes HTTP 500 / error. For this case I made change on one line in to_python() method.

def to_python(self, value):
    if (not value) or isinstance(value, datetime.timedelta):
        return datetime.timedelta(0)
    assert isinstance(value, (int, long,) ), (value, type(value))
    return datetime.timedelta(seconds=value)