fix management_form bug in sailors form

This commit is contained in:
maxime 2019-07-18 13:37:07 +02:00
parent bbc42ed5c5
commit a6f56cfcd3
3 changed files with 30 additions and 2 deletions

View File

@ -4,6 +4,8 @@
{% if sailors_forms.initial|length <= 0 %}
<em>No one is yet assigned for this boat</em>
{% else %}
<!-- necessary to work with formsets -->
{{ sailors_forms.management_form }}
Previous passengers :
<table>
@ -19,7 +21,8 @@
{% for sailors_form in sailors_forms %}
<tr>
{% with id=sailors_form.person.value %}
<td>{{ persons|get:id }}</td>
<td>{{ persons|get:id }}
{{ sailors_form.person }}</td>
{% endwith %}
<td>{{ sailors_form.is_captain }}</td>
<td>{{ sailors_form.is_crew }}</td>

View File

@ -0,0 +1,9 @@
{% extends "index.html" %}
{% load dict %}
{% block form %}
{{ stay_form }}
<br />
<input type="submit" value="Next" />
<br />
{% endif %}
{% endblock %}

View File

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