'How to cast DurationField to second in Django query

I have a model with a field defined like this:

mask_label_ts = models.DurationField(
    default=timedelta
)

In one of my query I'd like to multiply it by an integer, I aim at creating bill so I want to multiply the rate by hour by the nb of seconds.

How can I cast my duration field into seconds ?

I tried this:

test=ExpressionWrapper(F('mask_label_ts') * F('mask__labeller__hour_rate'), output_field=FloatField())

But this is not working.

Any ideas ? thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source