I have a model defined like below
class Event(models.Model):
room = models.ForeignKey(Room, on_delete=models.CASCADE)
start = models.DateField()
end = models.DateField()
I would like to setup constraints such that time span of each room's event is not intersect with each other.
For example:
- Event 1: Room A, date: [2024-01-01, 2024-01-05];
- Event 2: Room A, date: [2024-01-08, 2024-01-12]; <- Fine
- Event 3: Room A, date: [2024-01-04, 2024-01-07]. <- NOT fine
Event 3 is not fine because Room A is already occupied by Event 1 on Jan 4th and Jan 5th.
How can I achieve this with model constraints?