modyfikacja bazy + formularz dodawania klienta

This commit is contained in:
Hokan 2019-01-20 11:57:24 +01:00
parent 28f31ebe5b
commit 8f2563c734
9 changed files with 62 additions and 2 deletions

Binary file not shown.

15
hotel/rooms/forms.py Normal file
View File

@ -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: ')
}

View File

@ -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()

View File

@ -0,0 +1,16 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}">
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
</body>
</html>

View File

@ -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')
]

View File

@ -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.
@ -24,3 +25,14 @@ def reservation(request):
status = "Pokój " + str(room) + " jest już zarezerwowany"
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()