guys i want to tell my view that if a certail choice is selected end
the questionnaire or skip to a certain question but i am failing tho
retrieve the answer in the database  here are my views and other files
below.

so below i want to access the "if_this_answer_go_to_page" field and
check if there is a value there if the value exist then go to a page
where the question i want to go to exist.

#views.py

from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from django.template import RequestContext
from questions.models import Choice, Question

def index(request):
    latest_question_list = Question.objects.all()
    return render_to_response('questions/index.html',
{'latest_question_list': latest_question_list})

def detail(request, question_id):
        x = int(question_id)+1
        p = get_object_or_404(Question, pk=x)
        return render_to_response('questions/detail.html', {'question': p},
 
context_instance=RequestContext(request))

def results(request, question_id):
        p = get_object_or_404(Question, pk=question_id)
        return render_to_response('questions/results.html', {'question': p})

def saveQuestion(request, question_id):
    p = get_object_or_404(Question, pk=question_id)
    try:
        selected_choice = p.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        # Redisplay the question form.
        return render_to_response('questions/detail.html', {
            'question': p,
            'error_message': "You didn't select an answer.",
        }, context_instance=RequestContext(request))
    else:


                selected_choice.save()

                if Choice.if_this_answer_go_to_page:
                        return
HttpResponseRedirect(reverse('questions.views.results',args=(Choice.if_this_answer_go_to_page,)))
                else:
                        return 
HttpResponseRedirect(reverse('questions.views.detail',
args=(p.id,)))

        # Always return an HttpResponseRedirect after successfully
dealing
        # with POST data. This prevents data from being posted twice
if a
        # user hits the Back button.


#models.py


from django.db import models
import datetime

class Question(models.Model):
    quest = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    page_number =models.IntegerField(max_length=10)
    def was_published_today(self):
                return self.pub_date() == datetime.date.today()

    def __unicode__(self):
                return self.quest

class Choice(models.Model):
    question = models.ForeignKey(Question)
    choice = models.CharField(max_length=200)
    if_this_answer_go_to_page = models.CharField(max_length = 10,
                blank = True,
                null = True,
                )


    def __unicode__(self):
                return self.choice

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to