This is my first attempt at trying to code a form and use it in a
view, so I've probably got something wrong. At this point I just
wanted to produce the screen with all of the fields displayed on it,
just to see if I have things coded correctly to display the screen the
first time.

I'm not getting any error but I'm also not getting everything on my
screen which I think I should be getting. The screen should display a
title, then a message, a dropdown box(pollquestions), a button, and
finally another message. At least it should as long as I have my html
coded properly. My form is defined this way:

class AddChoiceForm(forms.Form):
    infomessage = forms.CharField(max_length=200)
    pollquestions =
forms.ModelChoiceField(queryset=Poll.objects.all(), required=True,
label='Poll Questions', initial='Please select a poll question',
help_text='Select a poll question.',
        error_messages={'required': 'Please select a poll question!',
'invalid_choice': 'Cannot select initial value!'},
        widget=forms.Select(attrs={'name': 'pollquestions',
'id':'pollquestions', 'size':'1', 'type':'select-one' }))
    confirmmessage = forms.CharField(max_length=200)
    newchoice = forms.CharField(max_length=200)


my addchoice.html screen is defined this way:

<h1>Add Poll Choice Screen</h1>

<form action="/polls/addchoice/" method="POST">
{% csrf_token %}

{{ infomessage }}

<br /><br />

{{ pollquestions }}

<br /><br />
<input type="submit" value="addchoice" />
<br /><br />

{{ confirmmessage }}

</form>

and my view is coded this way:

def addchoice(request):
    polls = Poll.objects.all()
    pollcount = Poll.objects.all().count()
    if pollcount > 0 :
        message = "Number of polls passed to form was " + str(pollcount)
    else:
        message = "No polls passed in to form."

    confirm = "Nothing added."

    data = {'pollquestions': polls, 'infomessage': message,
'confirmmessage': confirm }
    form = AddChoiceForm(data)
    dctnry = {'form': form, 'data': data}
    return render_to_response('polls/addchoice.html',
                              dctnry,
 
context_instance=RequestContext(request))


I would appreciate any help or suggestions, for figuring this out.
Thanks.








-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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