hi there hank23

to fix the problem you just need to send the queryset parameter to the
constructor of the ModelChoiceField

pollquestions = forms.ModelChoiceField(queryset=SomeModel, ...other
stuff...) works but

pollquestions = forms.ModelChoiceField(...other stuff without
queryset...) raises the exception you are getting

victor

On 7 jan, 20:28, hank23 <hversem...@stchas.edu> wrote:
> I have coded a new form with a ModelChoiceField defined on it which is
> getting the following error:
>
> TemplateSyntaxError at /admin/
> Caught TypeError while rendering: __init__() takes at least 2
> arguments (6 given)Request Method: GET
> Request URL:http://127.0.0.1:8000/admin/
> Django Version: 1.2.4
> Exception Type: TemplateSyntaxError
> Exception Value: Caught TypeError while rendering: __init__() takes at
> least 2 arguments (6 given)
> Exception Location: C:\Users\hversemann\djangoprojects\mysite\polls
> \forms.py in AddChoiceForm, line 7
> Python Executable: C:\Python27\python.exe
> Python Version: 2.7.1
> Python Path: ['C:\\Users\\hversemann\\djangoprojects\\mysite', 'C:\
> \Python\\Lib', 'C:\\Python\\Lib\\site-packages', 'C:\\Users\\hversemann
> \\Desktop\\PythonSourceFiles', 'C:\\Users\\hversemann\\djangoprojects\
> \mysite', 'C:\\WINDOWS\\system32\\python27.zip', 'C:\\Python27\\DLLs',
> 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\
> \lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']
> Server time:
>
> and here's the new form code itself, which it apparently doesn't like:
>
> 1.from django import forms
> 2.
> 3.class AddChoiceForm(forms.Form):
> 4.    infomessage = forms.CharField(max_length=200)
> 5.    pollquestions = forms.ModelChoiceField(required=True,
> label='Poll Questions', initial='Please select a poll  question',
> help_text='Select a poll question.',
> 6.        error_messages={'required': 'Please select a poll
> question!', 'invalid_choice': 'Cannot select initial value!'},
> 7.        widget=forms.Select(attrs={'name': 'pollquestions',
> 'id':'pollquestions', 'size':'1', 'type':'select-one' })) ...
> 8.    confirmmessage = forms.CharField(max_length=200)9.    newchoice
> = forms.CharField(max_length=200)
>
> I think I all of the parameters for the ModelChoiceField are legal
> based on the documentation, unless I have a typo somewhere. Thanks for
> looking. The help is much appreciated.

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