【发布时间】:2020-11-12 14:28:55
【问题描述】:
这个想法是将检查日期和结帐日期与从 html 文件中获得的检查日期和结帐日期进行比较(酒店预订,我正在尝试查看是否有可用的 habitaciones [房间])
****views.py 中的代码 *****
定义保留(请求):
pickerR = request.POST.get('pickerR', None)
pickerR_checkout = datetime.datetime.strptime(pickerR, '%d/%m/%Y') #convierto la fecha de tipo string a datetime
pickerL = request.POST.get('pickerL', None)
pickerL_checking = datetime.datetime.strptime(pickerL, '%d/%m/%Y') #convierto la fecha de tipo string a datetime
habitaciones = Habitacion.objects.all()
for hd in habitaciones:
if Habitacion[hd].fecha_checkout >= pickerL_checking and pickerR_checkout <= Habitacion[hd].fecha_checking:
cantHabitaciones = `enter code here`int(request.POST.get('cant_habitaciones'))
cantH = (request.POST.get('cant_huespedes'))
tipo_habitaciones = models.tipoHabitacion.objects.all()
#code in models.py
类 Habitacion(models.Model):
precio = models.IntegerField()
numero = models.IntegerField()
disponible = models.BooleanField()
tipo = models.ForeignKey(tipoHabitacion, on_delete=models.CASCADE)
fecha_checking = models.DateField('%d/%m/%Y')
fecha_checkout = models.DateField('%d/%m/%Y')
错误信息:
请求方法:POST 请求网址:http://127.0.0.1:8000/reservas.html/ Django 版本:3.1.1 异常类型:TypeError
异常值:'ModelBase' 对象不可下标
异常位置:/home/yamil/adaw2/hotel-Django/hotel/hotel/hotelApp1/views.py,第 94 行,预留 Python 可执行文件:/usr/bin/python3 Python 版本:3.8.5
- 如果 Habitacion[h].fecha_checkout
提前谢谢!!!
【问题讨论】:
-
您应该将代码和错误作为文本添加到帖子正文中 - 而不是图片。