[Answered ]-Django ORM query on fk set

1👍

You can enumerate over the dates, and ensure that it has for that date an Availability with closed=False:

from datetime import date, timedelta

rooms = Room.objects.all()
start_date = date(2022, 7, 21)  # first day
for dd in range(7):             # number of days
    dt = start_date + timedelta(days=dd)
    rooms = rooms.filter(availability__date=dt, availability__closed=False)

The rooms will after the for loop have a QuerySet with all Rooms that have for all dates in that range Availability objects with closed=False.

Leave a comment