Friday, January 3, 2020

Tweak admin widget - FilteredSelectMultiple

In the Admin where user group membership is shown and groups can be
selected from choices derived from auth_groups, I want to control the
available choices.

It seems the place to do so might be in admin/widgets.py in the
AutocompleteMixin.optgroups() method a few lines in where it says ...

        choices = (
            (obj.pk, self.choices.field.label_from_instance(obj))
            for obj in
self.choices.queryset.using(self.db).filter(pk__in=selected_choices)
        )

Could a very kind person explain to me how I can hijack this and remove
a couple of groups from the resulting choices?

My use case is that I want members of the 'admin' group to be able to
assign any group membershipto any other userexcept for a couple of
groups which are too permissive. The excepted groups can only be
assigned by a Superuser.

Many thanks for any hints

Cheers

Mike


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/52923a2a-cc6c-e335-f5fe-6ec6ab004013%40dewhirst.com.au.

No comments:

Post a Comment