[Django]-Django Admin SelectMultiple Widget

3👍

In your form class, you can specify a custom queryset for the group-field, which then determines which Group-instances are available in the form:

class UserForm(forms.ModelForm):
    # override the default groups field
    groups = forms.ModelMultipleChoiceField(
        queryset=Groups.objects.filter(YOUR_CONDITIONS),
        widget=forms.SelectMultiple,
    )

    class Meta:
        model = User

Leave a comment