diff --git a/hotel/rooms/__pycache__/forms.cpython-35.pyc b/hotel/rooms/__pycache__/forms.cpython-35.pyc new file mode 100644 index 0000000..8d32f1f Binary files /dev/null and b/hotel/rooms/__pycache__/forms.cpython-35.pyc differ diff --git a/hotel/rooms/__pycache__/models.cpython-35.pyc b/hotel/rooms/__pycache__/models.cpython-35.pyc index 386b93f..32e0797 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 5aa9817..20fb127 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 acb1b9e..e082e3e 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/forms.py b/hotel/rooms/forms.py new file mode 100644 index 0000000..05e3220 --- /dev/null +++ b/hotel/rooms/forms.py @@ -0,0 +1,15 @@ +from django.forms import ModelForm +from django.utils.translation import gettext_lazy as _ +from .models import * +from django import forms + + +class ClientForm(ModelForm): + class Meta: + model = Client + fields = '__all__' + labels = { + 'id_number': _('Numer dowodu: '), + 'name': _('Imię: '), + 'surname': _('Nazwisko: ') + } diff --git a/hotel/rooms/models.py b/hotel/rooms/models.py index add9c0e..98e320d 100644 --- a/hotel/rooms/models.py +++ b/hotel/rooms/models.py @@ -28,3 +28,19 @@ class Room(models.Model): def __str__(self): return str(self.room_number) + + +class Client(models.Model): + id_number = models.CharField(max_length=9, primary_key=True) + name = models.CharField(max_length=40) + surname = models.CharField(max_length=40) + + def __str__(self): + return self.name, self.surname + + +class Reservation(models.Model): + room_number = models.ForeignKey(Room, on_delete=models.CASCADE) + client_id = models.ForeignKey(Client, on_delete=models.CASCADE) + begin_date = models.DateField() + end_date = models.DateField() \ No newline at end of file diff --git a/hotel/rooms/templates/form.html b/hotel/rooms/templates/form.html new file mode 100644 index 0000000..9f9fd00 --- /dev/null +++ b/hotel/rooms/templates/form.html @@ -0,0 +1,16 @@ +{% load static %} + + + + + + Title + + +
+ {% csrf_token %} + {{ form.as_p }} + +
+ + \ No newline at end of file diff --git a/hotel/rooms/urls.py b/hotel/rooms/urls.py index d0e1047..1c1a2fe 100644 --- a/hotel/rooms/urls.py +++ b/hotel/rooms/urls.py @@ -4,5 +4,6 @@ from . import views urlpatterns = [ path('', views.index, name='index'), - path('reservation', views.reservation, name='reservation') + path('reservation', views.reservation, name='reservation'), + path('clientform', views.addclient, name='addclient') ] \ No newline at end of file diff --git a/hotel/rooms/views.py b/hotel/rooms/views.py index 0b453ae..5696531 100644 --- a/hotel/rooms/views.py +++ b/hotel/rooms/views.py @@ -2,6 +2,7 @@ from django.http import HttpResponse from django.template import loader from django.shortcuts import get_object_or_404, render from .models import * +from .forms import * # Create your views here. @@ -23,4 +24,15 @@ def reservation(request): else: status = "Pokój " + str(room) + " jest już zarezerwowany" - return HttpResponse(template.render({'status': status}, request)) \ No newline at end of file + return HttpResponse(template.render({'status': status}, request)) + + +def addclient(request): + if request.method == "GET": + form = ClientForm() + template = loader.get_template('form.html') + return HttpResponse(template.render({'form': form}, request)) + elif request.method == "POST": + client = ClientForm(request.POST) + client.save() + return HttpResponse() \ No newline at end of file