fix formularza klienta
This commit is contained in:
parent
570463a30b
commit
bc2db30129
BIN
hotel/db.sqlite3
BIN
hotel/db.sqlite3
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,6 @@ from django.db import models
|
|||||||
from django.core.validators import MinValueValidator, RegexValidator
|
from django.core.validators import MinValueValidator, RegexValidator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RoomType(models.Model):
|
class RoomType(models.Model):
|
||||||
room_type = models.CharField(max_length=40)
|
room_type = models.CharField(max_length=40)
|
||||||
|
|
||||||
@ -33,7 +32,6 @@ class Room(models.Model):
|
|||||||
class Client(models.Model):
|
class Client(models.Model):
|
||||||
id_number = models.CharField(max_length=9,
|
id_number = models.CharField(max_length=9,
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
|
|
||||||
name = models.CharField(max_length=40)
|
name = models.CharField(max_length=40)
|
||||||
surname = models.CharField(max_length=40)
|
surname = models.CharField(max_length=40)
|
||||||
|
|
||||||
@ -41,7 +39,6 @@ class Client(models.Model):
|
|||||||
return self.name + self.surname
|
return self.name + self.surname
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Reservation(models.Model):
|
class Reservation(models.Model):
|
||||||
room_number = models.ForeignKey(Room, on_delete=models.CASCADE)
|
room_number = models.ForeignKey(Room, on_delete=models.CASCADE)
|
||||||
client_id = models.ForeignKey(Client, on_delete=models.CASCADE)
|
client_id = models.ForeignKey(Client, on_delete=models.CASCADE)
|
||||||
|
@ -26,7 +26,6 @@ def index(request, page=1):
|
|||||||
|
|
||||||
rooms = rooms[10*(page-1):10*page]
|
rooms = rooms[10*(page-1):10*page]
|
||||||
template = loader.get_template('index.html')
|
template = loader.get_template('index.html')
|
||||||
print (first_page,last_page)
|
|
||||||
return HttpResponse(template.render({'rooms': rooms,
|
return HttpResponse(template.render({'rooms': rooms,
|
||||||
'firstpage': first_page,
|
'firstpage': first_page,
|
||||||
'lastpage': last_page,
|
'lastpage': last_page,
|
||||||
@ -50,10 +49,8 @@ def reservation(request):
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
begin = datetime.datetime.strptime(begin_date, "%d-%m-%Y")
|
begin = datetime.datetime.strptime(begin_date, "%d-%m-%Y")
|
||||||
end = datetime.datetime.strptime(end_date, "%d-%m-%Y")
|
end = datetime.datetime.strptime(end_date, "%d-%m-%Y")
|
||||||
try:
|
client_id = request.POST.get('id_number', False)
|
||||||
client_id = request.POST['id_number']
|
if client_id:
|
||||||
|
|
||||||
if Client.objects.filter(id_number=client_id).first() is None:
|
|
||||||
|
|
||||||
client = ClientForm(request.POST)
|
client = ClientForm(request.POST)
|
||||||
if client.is_valid():
|
if client.is_valid():
|
||||||
@ -62,7 +59,17 @@ def reservation(request):
|
|||||||
'name': client.cleaned_data['name'],
|
'name': client.cleaned_data['name'],
|
||||||
'surname': client.cleaned_data['surname']}
|
'surname': client.cleaned_data['surname']}
|
||||||
if check(id_number):
|
if check(id_number):
|
||||||
|
if Client.objects.filter(id_number=client_id).first() is None:
|
||||||
client.save()
|
client.save()
|
||||||
|
else:
|
||||||
|
error = "Zły numer dowodu"
|
||||||
|
form = ClientForm(initial=clientform)
|
||||||
|
template = loader.get_template('form.html')
|
||||||
|
return HttpResponse(template.render({'form': form,
|
||||||
|
'error': error,
|
||||||
|
'room_number': room_number,
|
||||||
|
'begin_date': begin_date,
|
||||||
|
'end_date': end_date}, request))
|
||||||
|
|
||||||
r = Reservation()
|
r = Reservation()
|
||||||
r.room_number = get_object_or_404(Room, room_number=room_number)
|
r.room_number = get_object_or_404(Room, room_number=room_number)
|
||||||
@ -74,9 +81,8 @@ def reservation(request):
|
|||||||
status = "Pokój " + str(room_number) + " został pomyślnie zarezerwowany"
|
status = "Pokój " + str(room_number) + " został pomyślnie zarezerwowany"
|
||||||
|
|
||||||
return HttpResponse(template.render({'status': status}, request))
|
return HttpResponse(template.render({'status': status}, request))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
error = "Zły numer dowodu"
|
|
||||||
except:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
form = ClientForm(initial=clientform)
|
form = ClientForm(initial=clientform)
|
||||||
|
Loading…
Reference in New Issue
Block a user