[Django]-Django & SQLite: DurationField arithmetics

3👍

If you get datetime.timedelta(0, 1800, 1800) instead of the correct datetime.timedelta(0, 3600) then you’re obviously almost there.

I would assume that the 1800 seconds are the difference between F("finish") and F("start"), while the 1800 microseconds come from F("penalty") * 60.

Multiply with 60*1000*1000 instead of 60 to convert penalty from minutes to microseconds:

total_time=ExpressionWrapper(
    F("finish") - F("start") + F("penalty") * 60000000,
    output_field=DurationField()
)

Leave a comment