[Fixed]-How to filter values in a drop down list django

1👍

Based on your forms.py code, i assume this is what you want:

class namesForm(forms.Form):
    names = forms.ModelChoiceField(
        queryset=Names.objects.exclude(name__in=['Josh','Tom']).order_by('name'),
        label = "Name:",
        widget = Select(attrs={'class': 'span6 small-margin-top small-margin-bottom'}),
        empty_label = "Select a Name",
        required=True
    )

Line I changed:

queryset=Names.objects.exclude(name__in=['Josh','Tom']).order_by('name'),

Documentation on using __in:
https://docs.djangoproject.com/en/1.10/ref/models/querysets/#in

Leave a comment