from django.shortcuts import render, redirect from django.urls import reverse from .models import InvitedGuest def index(request): return render(request, 'index.html') def rsvp(request): rsvpCode = request.GET['rsvp-code'] guests = InvitedGuest.objects.filter(rsvpCode = rsvpCode) if request.method == 'GET': return render (request, 'rsvp.html', {'guests':guests, 'rsvpCode': rsvpCode}) elif request.method == 'POST': any_attending = False for guest in guests: attending = request.POST['attending_%d' % guest.id] == 'attending' guest.attending = attending any_attending = any_attending or attending guest.save() return redirect(reverse('thank-you') + '?attending=' + ('yes' if any_attending else 'no')) def thanks(request): return render(request, 'thank-you.html', {'attending': request.GET.get('attending') == 'yes'})