podpiecie przycisku pod backend

This commit is contained in:
Hokan 2019-01-13 19:10:01 +01:00
parent eb49f18823
commit a2bc0b224e
9 changed files with 34 additions and 3 deletions

Binary file not shown.

View File

@ -25,3 +25,6 @@ class Room(models.Model):
room_type = models.ForeignKey(RoomType, on_delete=models.CASCADE) room_type = models.ForeignKey(RoomType, on_delete=models.CASCADE)
reserved = models.BooleanField() reserved = models.BooleanField()
def __str__(self):
return str(self.room_number)

View File

@ -23,9 +23,13 @@
{% if room.reserved %} {% if room.reserved %}
ZAREZERWOWANE ZAREZERWOWANE
{% else %} {% else %}
<div class="button-box" > <form action="{% url 'reservation' %}" method="POST">
<button>Zarezerwuj</button> {% csrf_token %}
</div> <input type="hidden" name="room" value="{{ room.room_number }}">
<div class="button-box" >
<button>Zarezerwuj</button>
</div>
</form>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>

View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{{ status }}
</body>
</html>

View File

@ -4,4 +4,5 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('reservation', views.reservation, name='reservation')
] ]

View File

@ -11,3 +11,16 @@ def index(request):
template = loader.get_template('index.html') template = loader.get_template('index.html')
return HttpResponse(template.render({'rooms': rooms}, request)) 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))