E
E
Empty User2020-02-25 18:12:00
Django
Empty User, 2020-02-25 18:12:00

Django. How to get entries that do not have a booking for a given period?

Ay nid yo help!
There is a Booking model with fields:

#Модель Booking
from_date = models.DateTimeField() #Дата начала бронирования
to_date = models.DateTimeField() #Дата конца бронирования
vehicle = models.ForeignKey(Vehicle .... # FK к модели автомобиля
confirmed = models.BooleanField(default=False) #Подвержденный или нет

So I can’t understand how you can get records with a list of vehicles (Vehicle), where there are no confirmed bookings (Booking) in the range "from" and "to"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2020-02-25
@deliro

The algorithm is as follows:
1. Take a sheet of paper
2. Draw your task on it
3. Strain the thing you usually eat in
4. It gives birth to a solution
If point number 4 did not work, change your profession

V
Vladimir, 2020-02-26
@Realmixer

If I understand you correctly:

free_vehicles = Vehicle.objects.filter(
    booking__confirmed=False, 
    booking__from_date__gte=datetime_from, 
    booking__to_date__lte=datetime_to,
)

Learn materiel .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question