On 5/01/2020 11:42 am, Mike Dewhirst wrote:
> 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.
Turns out the data I want to manipulate is encapsulated in widgets.py
FilteredSelectMultiple() where it returns context. That is called
directly from formfield_for_manytomany() so all I need to do is override
that in admin.py and tweak the context.
Thanks all who responded
Cheers
Mike
>
> 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 <miked@dewhirst.com.au
>> <mailto:miked@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+unsubscribe@googlegroups.com
>> <mailto:django-users%2Bunsubscribe@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.
>>
>> --
>> 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
>> <mailto:django-users+unsubscribe@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>.
>>
>
--
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/9dfed895-b926-0ef1-3945-000c79b43b40%40dewhirst.com.au.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment