0

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
    )
1

1 Answer 1

1

Posible duplicated question

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)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.