now = datetime.utcnow().replace(tzinfo=utc)
.annotate(
age=F(int((now - 'ended_at').total_seconds() / (60 * 60)))
I want to add logic like above in Django query. basically i want to calculate "age" that's a reason need to perform operation ORM. having large data and its taking time if I do this operation using for loop.
First define a
Functo extract the number of seconds since the UNIX epoch.Then make a query like this: