from django.http import HttpResponse from django.template import loader from django.shortcuts import get_object_or_404, render from .models import * # Create your views here. def index(request): rooms = Room.objects.all() template = loader.get_template('index.html') return HttpResponse(template.render({'rooms': rooms}, request)) def reservation(request): room = get_object_or_404(Room, room_number=request.POST['room']) template = loader.get_template('reservation.html') if not room.reserved: room.reserved = True room.save() status = "Pokój " + str(room) + " zarezerwowany pomyślnie" else: status = "Pokój " + str(room) + " jest już zarezerwowany" return HttpResponse(template.render({'status': status}, request))