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'
ChoiceFields don't take a queryset argument. You're looking for ModelChoiceField
.
queryset
is an argument for ModelChoiceField
. For ChoiceField
you want choices
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With