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
|
||||
|
||||
|
||||
|
||||
class RoomType(models.Model):
|
||||
room_type = models.CharField(max_length=40)
|
||||
|
||||
@ -33,7 +32,6 @@ class Room(models.Model):
|
||||
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)
|
||||
|
||||
@ -41,7 +39,6 @@ class Client(models.Model):
|
||||
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)
|
||||
|
@ -26,7 +26,6 @@ def index(request, page=1):
|
||||
|
||||
rooms = rooms[10*(page-1):10*page]
|
||||
template = loader.get_template('index.html')
|
||||
print (first_page,last_page)
|
||||
return HttpResponse(template.render({'rooms': rooms,
|
||||
'firstpage': first_page,
|
||||
'lastpage': last_page,
|
||||
@ -50,33 +49,40 @@ def reservation(request):
|
||||
if request.method == "POST":
|
||||
begin = datetime.datetime.strptime(begin_date, "%d-%m-%Y")
|
||||
end = datetime.datetime.strptime(end_date, "%d-%m-%Y")
|
||||
try:
|
||||
client_id = request.POST['id_number']
|
||||
client_id = request.POST.get('id_number', False)
|
||||
if client_id:
|
||||
|
||||
if Client.objects.filter(id_number=client_id).first() is None:
|
||||
|
||||
client = ClientForm(request.POST)
|
||||
if client.is_valid():
|
||||
id_number = client.cleaned_data['id_number']
|
||||
clientform = {'id_number': client.cleaned_data['id_number'],
|
||||
client = ClientForm(request.POST)
|
||||
if client.is_valid():
|
||||
id_number = client.cleaned_data['id_number']
|
||||
clientform = {'id_number': client.cleaned_data['id_number'],
|
||||
'name': client.cleaned_data['name'],
|
||||
'surname': client.cleaned_data['surname']}
|
||||
if check(id_number):
|
||||
client.save()
|
||||
|
||||
r = Reservation()
|
||||
r.room_number = get_object_or_404(Room, room_number=room_number)
|
||||
r.client_id = get_object_or_404(Client, id_number=client_id)
|
||||
r.begin_date = begin
|
||||
r.end_date = end
|
||||
r.save()
|
||||
|
||||
status = "Pokój " + str(room_number) + " został pomyślnie zarezerwowany"
|
||||
|
||||
return HttpResponse(template.render({'status': status}, request))
|
||||
if Client.objects.filter(id_number=client_id).first() is None:
|
||||
client.save()
|
||||
else:
|
||||
error = "Zły numer dowodu"
|
||||
except:
|
||||
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.room_number = get_object_or_404(Room, room_number=room_number)
|
||||
r.client_id = get_object_or_404(Client, id_number=client_id)
|
||||
r.begin_date = begin
|
||||
r.end_date = end
|
||||
r.save()
|
||||
|
||||
status = "Pokój " + str(room_number) + " został pomyślnie zarezerwowany"
|
||||
|
||||
return HttpResponse(template.render({'status': status}, request))
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
form = ClientForm(initial=clientform)
|
||||
|
Loading…
Reference in New Issue
Block a user