I am expanding on the basic django Poll site tutorial, and I have made a view that allows users to add their own polls. Adding a poll works, adding choices does not. Apparently this is because the poll does not "exist" yet, and the p.id cannot be used. However, the p.id works when redirecting the browser at the bottom. Anyy ideas?
def save(request):
p = Poll(question=request.POST['question'], pub_date=timezone.now())
p.save()
c1 = Choice(poll=p.id, choice_text=request.POST['c1'], votes=0)
c2 = Choice(poll=p.id, choice_text=request.POST['c2'], votes=0)
c3 = Choice(poll=p.id, choice_text=request.POST['c3'], votes=0)
c4 = Choice(poll=p.id, choice_text=request.POST['c4'], votes=0)
c1.save()
c2.save()
c3.save()
c4.save()
return HttpResponseRedirect(reverse('detail', args=(p.id,)))