Reputation: 2240
In my django project, I have a model with a Postgres DateTimeRangeField holding the time lapse between the start and the end of a long task. Something like this:
timespan = DateTimeRangeField()
Is it possible to use order_by on the queryset using either the lower or upper attributes of the range field?
Upvotes: 2
Views: 1815
Reputation: 51665
Using either the lower or upper attributes of the range field is the order by
default behaviour. Quoting DateTimeRangeField django docs:
Range fields support the standard lookups: lt, gt, lte and gte. These are not particularly helpful - they compare the lower bounds first and then the upper bounds only if necessary. This is also the strategy used to order by a range field. It is better to use the specific range comparison operators
Upvotes: 1