Reputation: 261
How can i make a queryset in this modelform. This is my code.
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)}
Is this the right way in using queryset? Pls help me.
Thank You.
Upvotes: 0
Views: 1390
Reputation: 22808
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)
Upvotes: 2