I have a basic form that shows what a person entered when it is
submitted.  However, it shows up as a form.CharField (textbox) instead
of model.CharField. Is there a way to access the model's saved data
from the Forms? Also does form_for_model (http://www.djangobook.com/en/
1.0/chapter07/) no longer exist? I can't get it to load.

models.py:
from django.db import models
from django.forms import ModelForm

class Question(models.Model):
        question = models.CharField('Question', max_length = '200',
primary_key = True)
        pub_date = models.DateField(auto_now_add = True)
        def __unicode__(self):
                return self.question

class Choice(models.Model):
        Question = models.ForeignKey(Question)
        choice = models.CharField(max_length = '200')

class Questionform(ModelForm):
        class Meta:
                model = Question
class Choiceform(ModelForm):
        class Meta:
                model = Choice

view:
from qotd.models import *
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect

def contact(request, question):
    if request.method == 'POST': # If the form has been submitted...
        form = Questionform(request.POST) # A form bound to the POST
data
        if form.is_valid():
                form.save()
                #return HttpResponseRedirect('results.html', {'form': form}

    else:
        form = Questionform()
    return render_to_response('contact.html', {
        'form': form
    })
template:

<html>
{% if not form.is_valid %}
<form action="/contact/" method="POST">
{{ form.as_p }}
<input type="submit" value="Submit" />
{% endif %}
{% if form.is_valid %}
{{ form.question }}
{% endif %}

</form>
</html>

--~--~---------~--~----~------------~-------~--~----~
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