From 0c905da8af5b1f3a85a1a0b06a5914c479e5c135 Mon Sep 17 00:00:00 2001 From: Drew Larson Date: Mon, 30 May 2016 20:32:17 -0600 Subject: [PATCH] Allow for new or editing. --- bikeshop_project/registration/templates/edit_member_form.html | 1 + bikeshop_project/registration/views.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/bikeshop_project/registration/templates/edit_member_form.html b/bikeshop_project/registration/templates/edit_member_form.html index 288e25f..a89749c 100644 --- a/bikeshop_project/registration/templates/edit_member_form.html +++ b/bikeshop_project/registration/templates/edit_member_form.html @@ -192,6 +192,7 @@ {% if not form.instance.membership %}

No membership found.

+ Add membership
{% endif %} {% endblock %} diff --git a/bikeshop_project/registration/views.py b/bikeshop_project/registration/views.py index 03e0582..3d1f983 100644 --- a/bikeshop_project/registration/views.py +++ b/bikeshop_project/registration/views.py @@ -22,6 +22,7 @@ class MemberFormView(View): context = dict(form=form) if member: + context['member'] = member return TemplateResponse(request, 'edit_member_form.html', context=context) return TemplateResponse(request, 'member_form.html', context=context) @@ -31,6 +32,7 @@ class MemberFormView(View): member = Member.objects.get(id=member_id) form = MemberForm(request.POST, instance=member) except Member.DoesNotExist: + member = None form = MemberForm(request.POST) logger.debug(form) if form.is_valid(): @@ -41,4 +43,6 @@ class MemberFormView(View): logger.debug(form) context = {'form': form} + if member: + context['member'] = member return TemplateResponse(request, 'member_form.html', context=context)