[Answered ]-Django: Filter based on foreignkey's start date and end date

1👍

Two intervals [s1, e1] and [s2, e2] do not overlap if s1 > e2 or s2 > e1.

We thus can check this with:

from django.db.models import F, Q

ChildModel.objects.filter(
    Q(start_date__gt=F('parent_model__end_date')) |
    Q(end_date__lt=F('parent_model__start_date'))
)

Leave a comment