Reputation: 5227
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'
Upvotes: 5
Views: 9915
Reputation: 2439
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
Upvotes: 2
Reputation: 85683
queryset
is an argument for ModelChoiceField
. For ChoiceField
you want choices
Upvotes: 4
Reputation: 599876
ChoiceFields don't take a queryset argument. You're looking for ModelChoiceField
.
Upvotes: 9