diff --git a/hotel/db.sqlite3 b/hotel/db.sqlite3 index abcf312..0ba0880 100644 Binary files a/hotel/db.sqlite3 and b/hotel/db.sqlite3 differ diff --git a/hotel/rooms/__pycache__/models.cpython-35.pyc b/hotel/rooms/__pycache__/models.cpython-35.pyc index 930053f..386b93f 100644 Binary files a/hotel/rooms/__pycache__/models.cpython-35.pyc and b/hotel/rooms/__pycache__/models.cpython-35.pyc differ diff --git a/hotel/rooms/__pycache__/urls.cpython-35.pyc b/hotel/rooms/__pycache__/urls.cpython-35.pyc index b9f2f28..5aa9817 100644 Binary files a/hotel/rooms/__pycache__/urls.cpython-35.pyc and b/hotel/rooms/__pycache__/urls.cpython-35.pyc differ diff --git a/hotel/rooms/__pycache__/views.cpython-35.pyc b/hotel/rooms/__pycache__/views.cpython-35.pyc index 3ab7a68..acb1b9e 100644 Binary files a/hotel/rooms/__pycache__/views.cpython-35.pyc and b/hotel/rooms/__pycache__/views.cpython-35.pyc differ diff --git a/hotel/rooms/models.py b/hotel/rooms/models.py index 150f282..add9c0e 100644 --- a/hotel/rooms/models.py +++ b/hotel/rooms/models.py @@ -25,3 +25,6 @@ class Room(models.Model): room_type = models.ForeignKey(RoomType, on_delete=models.CASCADE) reserved = models.BooleanField() + + def __str__(self): + return str(self.room_number) diff --git a/hotel/rooms/templates/index.html b/hotel/rooms/templates/index.html index 1b1dbac..6a3b8d6 100644 --- a/hotel/rooms/templates/index.html +++ b/hotel/rooms/templates/index.html @@ -23,9 +23,13 @@ {% if room.reserved %} ZAREZERWOWANE {% else %} -
- -
+
+ {% csrf_token %} + +
+ +
+
{% endif %} diff --git a/hotel/rooms/templates/reservation.html b/hotel/rooms/templates/reservation.html new file mode 100644 index 0000000..c0ba886 --- /dev/null +++ b/hotel/rooms/templates/reservation.html @@ -0,0 +1,10 @@ + + + + + Title + + +{{ status }} + + \ No newline at end of file diff --git a/hotel/rooms/urls.py b/hotel/rooms/urls.py index 3ef24d9..d0e1047 100644 --- a/hotel/rooms/urls.py +++ b/hotel/rooms/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path('', views.index, name='index'), + path('reservation', views.reservation, name='reservation') ] \ No newline at end of file diff --git a/hotel/rooms/views.py b/hotel/rooms/views.py index 5af244b..0b453ae 100644 --- a/hotel/rooms/views.py +++ b/hotel/rooms/views.py @@ -11,3 +11,16 @@ def index(request): 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)) \ No newline at end of file