Search code examples
djangodatetimerangefield

Django DateTimeRangeField how to filter by lower only?


Let's say I have a model with the DateTimeRangeField, and I would like to filter by the lower bound greater than now(), regardless whatupper bound is:

BackupResource.objects.filter(datetime_range__lower__gt=timezone.now())

It errors out:

Unsupported lookup 'lower' for DateTimeRangeField or join on the field not permitted.

Solution

  • Try doing the following

    BackupResource.objects.filter(datetime_range__startswith__gt=timezone.now())