podpiecie przycisku pod backend
This commit is contained in:
parent
eb49f18823
commit
a2bc0b224e
BIN
hotel/db.sqlite3
BIN
hotel/db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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)
|
||||||
|
@ -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>
|
||||||
|
10
hotel/rooms/templates/reservation.html
Normal file
10
hotel/rooms/templates/reservation.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{ status }}
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -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')
|
||||||
]
|
]
|
@ -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))
|
Loading…
Reference in New Issue
Block a user