modyfikacja bazy + formularz dodawania klienta
This commit is contained in:
parent
28f31ebe5b
commit
8f2563c734
BIN
hotel/rooms/__pycache__/forms.cpython-35.pyc
Normal file
BIN
hotel/rooms/__pycache__/forms.cpython-35.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15
hotel/rooms/forms.py
Normal file
15
hotel/rooms/forms.py
Normal 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: ')
|
||||
}
|
@ -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()
|
16
hotel/rooms/templates/form.html
Normal file
16
hotel/rooms/templates/form.html
Normal 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>
|
@ -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')
|
||||
]
|
@ -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()
|
Loading…
Reference in New Issue
Block a user