Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django form "unexpected keyword argument 'queryset'"

I'm probably doing something obviously wrong here like missing an import.

from django import forms  
from swap_meet.inventory.models import Item 

class AddOrderForm(forms.Form):
    test = forms.ChoiceField(queryset=Item.objects.all())

Error I get is __init__() got an unexpected keyword argument 'queryset'

like image 605
deadghost Avatar asked Jan 15 '12 17:01

deadghost


3 Answers

ChoiceFields don't take a queryset argument. You're looking for ModelChoiceField.

like image 67
Daniel Roseman Avatar answered Nov 18 '22 16:11

Daniel Roseman


queryset is an argument for ModelChoiceField. For ChoiceField you want choices

like image 30
joaquin Avatar answered Nov 18 '22 16:11

joaquin


For ChoiceField you can use

    test = forms.ChoiceField(choices=[
    (item.pk, item) for item in Item.objects.all()])

In general choices are a list of tuples

like image 1
Dimitris Kougioumtzis Avatar answered Nov 18 '22 16:11

Dimitris Kougioumtzis