How to annotate a difference of datetime in days
I have a Booking model that has start and end datetime fields. I want to know how many days a booking covers. I can do this in Python but I need this value for further annotations. Here's what I've tried: In [1]: Booking.objects.annotate(days=F('end')-F('start'))[0].days Out[1]: datetime.timedelta(16, 50400) There are a few problems here: I want an integer (or other number type I can use in calculations) of days as the output, not a timedelta. Setting output_field doesn't do anything meaningful here. My sums are based on date times . Subtractions like this, without removing the time could lead