djangodjango-modelsdjango-postgresql

How can I query a Postgres DateRange with a single date?


I am using django.contrib.postgres.field.DateRangeField as described [here][1].

class MyModel(models.Model):
    date_range = DateRangeField()

How to I query this model to return all date_range with a lower bound greater than today?

I tried:

today = datetime.date.today()
MyModel.objects.filter(date_range__gt=today)

But this results in operator does not exist: daterange > date.


Solution

  • MyModel.objects.filter(date_range__contains=today)