From a6f56cfcd37c05a6418df17d71dc763eb1887b3a Mon Sep 17 00:00:00 2001 From: maxime Date: Thu, 18 Jul 2019 13:37:07 +0200 Subject: [PATCH] fix management_form bug in sailors form --- port/templates/new_stay/new_stay-2.html | 5 ++++- port/templates/new_stay/new_stay-3.html | 9 +++++++++ port/views/index.py | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 port/templates/new_stay/new_stay-3.html diff --git a/port/templates/new_stay/new_stay-2.html b/port/templates/new_stay/new_stay-2.html index 0cbfc96..7d3a33e 100644 --- a/port/templates/new_stay/new_stay-2.html +++ b/port/templates/new_stay/new_stay-2.html @@ -4,6 +4,8 @@ {% if sailors_forms.initial|length <= 0 %} No one is yet assigned for this boat {% else %} + + {{ sailors_forms.management_form }} Previous passengers : @@ -19,7 +21,8 @@ {% for sailors_form in sailors_forms %} {% with id=sailors_form.person.value %} - + {% endwith %} diff --git a/port/templates/new_stay/new_stay-3.html b/port/templates/new_stay/new_stay-3.html new file mode 100644 index 0000000..187dce1 --- /dev/null +++ b/port/templates/new_stay/new_stay-3.html @@ -0,0 +1,9 @@ +{% extends "index.html" %} +{% load dict %} +{% block form %} + {{ stay_form }} +
+ +
+ {% endif %} +{% endblock %} diff --git a/port/views/index.py b/port/views/index.py index 7aec4be..130f287 100644 --- a/port/views/index.py +++ b/port/views/index.py @@ -112,6 +112,19 @@ def new_stay_1(request): def new_stay_2(request): # Person + if request.method == 'POST': + sailors_forms = SailorsFormSet(data=request.POST, + prefix='sai') + + for sailor_form in sailors_forms: + if not sailor_form.is_valid(): + return render(request, 'new_stay/new_stay-2.html') + else: + sailor = sailor_form.save(commit=False) + sailor.boat_id = request.session['new_stay_boat'] + sailor.save() + return new_stay_3(request) + boat = Boat.objects.get( pk=request.session.get('new_stay_boat')) @@ -139,6 +152,9 @@ def new_stay_2(request): return render(request, 'new_stay/new_stay-2.html', data) def new_stay_3(request): - pass + if request.method == 'POST': + pass + + return render(request, 'new_stay/new_stay-3.html', data) def new_stay_4(request): pass
{{ persons|get:id }}{{ persons|get:id }} + {{ sailors_form.person }}{{ sailors_form.is_captain }} {{ sailors_form.is_crew }}