Greg
Greg

Reputation: 47164

Django - ModelChoiceField - TypeError - __init__() takes at least 2 arguments (1 given)

I'm on Django 1.2. I'm trying to use the ModelChoiceField in a form. Why are these failing with the above error message? I'm at a loss :-(

class QueueForm(forms.Form):
    queue = forms.ModelChoiceField(query_set=Order.objects.all())

I also tried this:

class QueueForm(forms.Form):
    queue = forms.ModelChoiceField(query_set=Order.objects.all(),required=False)

And got:

__init__() takes at least 2 arguments (2 given)

It seems to be saying this is happening on the queue = .. line. Before I even use the form.

Upvotes: 1

Views: 5221

Answers (1)

checker
checker

Reputation: 531

You're setting the wrong variable name in the constructor, it needs to be queryset and not query_set. Try this:

class QueueForm(forms.Form):
queue = forms.ModelChoiceField(queryset=Order.objects.all())

Upvotes: 7

Related Questions