2013-08-21 24 views
2

我正在嘗試創建一個由queryset填充的多選字段。多選字段在django中不顯示queryset

我的形式如下:

class GroupLocationForm(forms.Form): 
    groups_field = forms.MultipleChoiceField(required=False, 
            widget=forms.CheckboxSelectMultiple) 

    def __init__(self, customer_id, group_id): 
     super(GroupLocationForm, self).__init__() 
     customer = Customer.objects.get(pk=customer_id) 

     self.fields['groups_field'].queryset = Group.objects.filter(location__customer = customer).distinct() 

沒有在我的形式選擇方面出現了。如果我添加:

MY_CHOICES = (
        (1,'choice 1'), 
) 

groups_field = forms.MultipleChoiceField(required=False, 
            widget=forms.CheckboxSelectMultiple, choices=MY_CHOICES) 

該選擇顯示沒有任何問題。

爲什麼我的查詢集沒有分配給小部件?

回答

相關問題