2012-01-15 165 views
3

我可能在做這樣的事情顯然是錯誤的,就像缺少一個導入。django形式「意外的關鍵字參數」查詢集「」

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

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

錯誤我得到的是__init__() got an unexpected keyword argument 'queryset'

回答

7

ChoiceFields不帶走一片的queryset參數。您正在尋找ModelChoiceField

0

對於ChoiceField可以使用

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

一般的選擇是元組

列表
相關問題