Ok, here is my 'Modelform' problem:

I want to redirect based on selected choice from simple form:

QUESTION
        OPTIONS: 1, 2, 3

Obviously, by me chosen approach with 'get.objects.latest' is not the
one, that works...

Somebody have an idea?

Thanks

views.py

from django.shortcuts import render_to_response
from api.q1.forms import QuestionForm
from api.q1.models import Question

def index(request):
        if request.method == 'POST':
                form = QuestionForm(request.POST)
                if form.is_valid():
                        form.save()
                        a = Question.objects.latest('color')
                        if a.color == 'BLUE':
                                return render_to_response('q1/a1.html')
                        elif a.color == 'RED':
                                return render_to_response('q1/a2.html')
                        elif a.color == 'WHITE':
                                return render_to_response('q1/a3.html')
                        else:
                                return render_to_response('q1/thanks.html')
        else:
                form = QuestionForm()

        return render_to_response('q1/q.html', {'form': form})

models.py

from django.db import models

COLOR_CHOICES = (
        ('BLUE', 'Blue'),
        ('RED', 'Red'),
        ('WHITE', 'White'),
)


class Question(models.Model):
        color = models.CharField("What's your favorite color?",
max_length=255, choices=COLOR_CHOICES)

        def __unicode__(self):
                return self.color

        class Admin:
                pass

forms.py

from q1.models import Question
from django.newforms import ModelForm
from django.newforms.widgets import *

class QuestionForm(ModelForm):
        class Meta:
                model = Question

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to