E
E
Empty User2020-02-13 18:24:10
Django
Empty User, 2020-02-13 18:24:10

Django. How to check if a period of time is included in another period?

Good day!
There are booking records where there are two parameters from_date, to_date. When adding a new booking, there are the same parameters, and it checks if there are any records that relate to this interval, if found, return FALSE, and if free, then TRUE.
For example, there are records:
A) from 02/14/2020 to 02/19/2020
B) from

02/20/2020 to 02/23/2020 2020 - 02/21/2020 FALSE 4) 02/08/2020 - 02/13/2020 TRUE 5) 02/24/2020 - 02/29/2020 TRUE Only this came to mind, but it does not work correctly, already the brains are boiling)

qs = Booking.objects.filter(status__in=[BookingStatus.CONFIRMED, BookingStatus.PAYED, BookingStatus.ACTIVE])\
.filter(Q(from_date__range=(from_date, to_date)) | Q(to_date__range=(from_date, to_date))) \
.count()

Plz, help! Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2020-02-13
@dimonchik2013

the problem is that xs how did you design the base / model
because nothing new , you only need to check for more than less than two dates

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question