我正在构建一个酒店管理系统,我已经编写了一个 check_availability 函数,该函数将根据客户要求的类别检查房间是否为空,但事实证明该函数忽略了数据库,因为它只关心现有的一个不是添加的一个。这是代码:
从 django.db 导入模型
from django.contrib.auth.models import User
class RoomCategory(models.Model):
name = models.CharField(max_length=59)
price = models.IntegerField()
beds = models.PositiveIntegerField()
capacity = models.PositiveIntegerField()
size = models.CharField(max_length=59)
def __str__(self):
return self.name
class Room(models.Model):
room_number = models.CharField(max_length=60)
room_category = models.ForeignKey(RoomCategory, on_delete=models.CASCADE)
def __str__(self):
return f"The room {self.room_number} {self.room_category} has a maximum of {self.room_category.capacity} person and cost {self.room_category.price}/night "
class Booking(models.Model):
customer = models.ForeignKey(User, on_delete=models.CASCADE)
room = models.ForeignKey(Room, on_delete=models.CASCADE)
check_in = models.DateTimeField()
check_out = models.DateTimeField()
def __str__(self):
return f"{self.customer} has booked for a {self.room} room from {self.check_in} to {self.check_out}"
from django.shortcuts import render
from .forms import BookingForm
from .models import Booking, RoomCategory, Room
from django.views.generic import FormView
from Hotel.Availabililty.Available import check_availability
from django.http import HttpResponse
# Create your views here.
class BookingFormview(FormView):
form_class = BookingForm
template_name = 'Hotel/bookingformview.html'
)
心有法竹
相关分类