[Python] Filter Django RangeField by comparing to a point, not to another range

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    The PostgreSQL specific model fields docs are very specific about how to compare one RangeField to another range. But how do you compare a range to a single point?

    For example, if I've got a model with valid_range=DateTimeRangeField, and I want to find all instances which are no longer valid, I need to do something like:

    from django.utils import timezone as tz

    MyProduct.objects.filter(valid_range__lt=tz.now())


    But this isn't allowed. I thought I could use fully_lt but that's not allowed with a particular date either.

    How do I filter a DateTimeRangeField to find instances whose ranges ended before a certain datetime?

    Continue reading...

Compartilhe esta Página