Hello,
I’m building a room rent site, so I have these models:
class Hotels(models.Model):
name = models.CharField(max_length=30, unique=True)
slug = models.SlugField(max_length=30, unique=True)
user = models.ForeignKey(Account, on_delete=models.CASCADE)
address = models.CharField(max_length=150)
website = models.CharField(max_length=100, blank=True, null=True)
email = models.EmailField()
phone = models.CharField(max_length=13)
available = models.BooleanField(default=False)
description = models.TextField(blank=True, max_length=1000)
logo = models.ImageField(upload_to=‘Restaurant_Logos’)
date_added = models.DateTimeField(auto_now_add=True)class Rooms(models.Model):
number = models.CharField(max_length=20)
slug = models.SlugField(max_length=20)
hotel = models.ForeignKey(Hotels, on_delete=models.CASCADE)
seats = models.PositiveIntegerField()
available = models.BooleanField(default=True)class Reservations(models.Model):
number = models.PositiveIntegerField()
hotel = models.ForeignKey(Hotels, on_delete=models.CASCADE)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
room = models.ForeignKey(Room, on_delete=models.CASCADE)
people = models.PositiveIntegerField()
price = models.DecimalField()
date_time = models.DateTimeField()
created_at = models.DateTimeField(auto_now_add=True)
I will have more than one hotel on the site, every of them will have their rooms.
When somebody reserve a room, the rooms will be reserved only for 2 hours not for a whole day.
On the page I’m building there is a filter menu with date and time pickers,
So my question is, How to filter all the rooms throght the Reservation model, so I can display the hotels that have a free room on this day and hour?
But if somebody wants to reserve a room, this room shouldn’t be reserved 2 hours prior and 2 hours afterwards the given date/time from the user because all the rooms are reserved for 2 hours.
So I have to filter the hotels with that exception in mind.
If anybody help me I’m gonna be really gratefull.
Thank you!