I need to discover interval for begin_date
and end_date
fields of my model
class Reserved(models.Model):
begin_date = models.DateTimeField()
end_date = models.DateTimeField()
In short when user is saving some data to the database in forms should be validation. Validation should to check is there reservation in interval begin_date
and end_date
and give error.
I tried to to this but it does not work :(
def save(self, commit=True):
date_validation = Reserved.objects.filter(room=self.room).exists() and \
Reserved.objects.filter(
begin_date__gte=datetime.date.today(),
end_date__lte=datetime.date.today()
)
if date_validation:
raise RuntimeError('You can not reserve this room. Interval')
super(ReserveRoomForm, self).save(commit)
For example the there are reservation in begin date 23-January and end date 29-January but user trying to reserve 25-January
How to realize it? Thanks)