Reputation: 17
I have a choice field on a form I am trying to display all the cars in a drop down list that are the same color, the color chosen is defined by a user input field
class car(forms.Form,email):
cars = forms.ModelChoiceField(
empty_label = "Current Cars",
queryset = Cars.objects.order_by('name').filter(color=color),
widget = Select(attrs={'class': 'span6 small-margin-top small-margin-bottom'}),
required=True
)
Upvotes: 0
Views: 266
Reputation: 1559
class AccountDetailsForm(forms.Form):
...
adminuser = forms.ModelChoiceField(queryset=User.objects.all())
def __init__(self, *args, **kwargs):
accountid = kwargs.pop('accountid', None)
super(AccountDetailsForm, self).__init__(*args, **kwargs)
if accountid:
self.fields['adminuser'].queryset = User.objects.filter(account=accountid)
form = AccountDetailsForm(accountid=3)
Upvotes: 1