2013-04-13 100 views
0

如何在此模型中創建一個查詢集。這是我的代碼。形式的Django Queryset

Class Sample(forms.ModelForm): 
    class Meta: 
     model = Customer 
     fields = ('name','address',) 
     widgets = { 
      'name' : Select(attrs={'class':'span2'}), 
      'address' : TextInput(attrs={'class':'span4'}), 
      } 
     queryset = {'name': User.objects.filter(type_id=1)} 

這是使用queryset的正確方法嗎?請幫助我。

謝謝。

回答

2
Class Sample(forms.ModelForm): 
    class Meta: 
     model = Customer 
     fields = ('name','address',) 
     widgets = { 
      'name' : Select(attrs={'class':'span2'}), 
      'address' : TextInput(attrs={'class':'span4'}), 
      } 

    def __init__(self, *args, **kwargs): 
     super(Sample, self).__init__(*args, **kwargs) 
     self.fields['name'].queryset = User.objects.filter(type_id=1) 
+0

非常感謝你.. :-) – Nethan

+0

歡迎........ – catherine