On 4/01/2020 9:03 pm, Integr@te System wrote:
> Hi Mike,
>
> As we look at selected_choice result from iterating v over value (line
> 428), option_value base on choice(line 438).
> so we can limit input parameter of value variable from this def().
selected_choices appear in the selected box on screen and choices appear
in the available choices box.
I can see how to tweak either of those if the method was my own. But it
is an Admin method which interfaces with javascript to provide the user
interface for making those selections.
I think my original question was too brief.
I'm thinking now I should be using my own version of AutocompleteMixin
somehow and use formfield_for_manytomany when db_field == "groups" in my
admin.py to get access to it.
formfield_for_manytomany calls the AutocompleteSelectMultiple class
which inherits AutocompleteMixin which has the optgroups() method which
contains selected_choices and choices which are of interest to me.
That said, my question really is "Huh! How do I do that?"
Maybe I'll do some experiments
Thanks in advance if you can short-circuit my research
Cheers
Mike
>
> Hope if heplful.
>
>
>
> On Sat, Jan 4, 2020, 11:00 Mike Dewhirst <
mi...@dewhirst.com.au
> <mailto:
mi...@dewhirst.com.au>> wrote:
>
> 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 <
http://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...@googlegroups.com
> <mailto:
django-users%2Bunsu...@googlegroups.com>.
> --
> 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...@googlegroups.com
> <mailto:
django-users...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/CAP5HUWoZ14gH%3D8V1ARk-pnAKNWuVaqG%3D4%3DGSbwO_-0LrP7DFnw%40mail.gmail.com
> <
https://groups.google.com/d/msgid/django-users/CAP5HUWoZ14gH%3D8V1ARk-pnAKNWuVaqG%3D4%3DGSbwO_-0LrP7DFnw%40mail.gmail.com?utm_medium=email&utm_source=footer>.