Код: Выделить всё
@csrf_exempt
def bookings(request):
if request.method == 'POST':
data = json.load(request)
exist = Reservation.objects.filter(reservation_date=data['reservation_date']).filter(
reservation_slot=data['reservation_slot']).exists()
if exist==False:
booking = Reservation(
name=data['first_name'],
phone_number=data['phone_number'],
email=data['email'],
reservation_date=data['reservation_date'],
reservation_slot=data['reservation_slot'],
)
booking.save()
else:
return HttpResponse("{'error':1}", content_type='application/json')
date = request.GET.get('date',datetime.today().date())
bookings = Reservation.objects.all().filter(reservation_date=date)
booking_json = serializers.serialize('json', bookings)
return HttpResponse(booking_json, content_type='application/json')
Код: Выделить всё
class Reservation(models.Model):
name = models.CharField(max_length=100)
phone_number = models.IntegerField()
email = models.EmailField()
reservation_date = models.DateField()
reservation_slot = models.SmallIntegerField(default=10)
def __str__(self):
return self.name + " " + self.surname
Код: Выделить всё
class ReservationForm(ModelForm):
class Meta:
model = Reservation
fields = "__all__"
Код: Выделить всё
File "/home/prabhu/Documents/Projects/alcudia-web/my_alcudia/baseweb/views.py", line 50, in bookings
email=data['email'],
KeyError: 'email'
Код: Выделить всё
Email:
Подробнее здесь: https://stackoverflow.com/questions/771 ... -in-django