def submit_poll(request): question = request.POST['question'] number = int(request.POST['num_choices']) end_date = request.POST['end_date'] errors = [] if not question or not number: if not question: errors.append("You didn't put a question") if not number: errors.append("You didn't specify a number of options") if not end_date: errors.append("You didn't specify an end date for the poll") return render(request, 'polls/poll_creation.html', {'error_message': errors}) else: poll = Poll() poll.question = question poll.pub_date = timezone.now() poll.start_date = timezone.now() poll.end_date = end_date poll.save() return HttpResponseRedirect( reverse('polls:option_creation', args=(number, poll.id)))
def submit_poll(request): question = request.POST['question'] number = int(request.POST['num_choices']) end_date = request.POST['end_date'] errors = [] if not question or not number: if not question: errors.append("You didn't put a question") if not number: errors.append("You didn't specify a number of options") if not end_date: errors.append("You didn't specify an end date for the poll") return render(request, 'polls/poll_creation.html', { 'error_message': errors }) else: poll = Poll() poll.question=question poll.pub_date=timezone.now() poll.start_date=timezone.now() poll.end_date=end_date poll.save() return HttpResponseRedirect(reverse('polls:option_creation', args=(number, poll.id)))