﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29742	Problem overriding the FilteredSelectMultiple widget	Bryant Glisson	nobody	"We have overridden the FilteredSelectMultiple widget here.
https://github.com/django/django/blob/201017df308266c7d5ed20181e6d0ffa5832e3e9/django/contrib/admin/widgets.py

We also override the form in which the widget is used in order to pass custom choices to it, using the following.

{{{
CHOICES = [(1, ""One""), (2, ""Two""), (3, ""Three"")]]
self.fields['topics'].widget = AdminTagsWidget('Topics', False, choices=CHOICES)
}}}

When we load the form, we get the following error:

TypeError at /site-admin/media/mediaitem/302444/change/
int() argument must be a string, a bytes-like object or a number, not 'list'

After much tinkering, I discovered that ""self.is_stacked"" is being filled with ""self.choices"" and is being used to populate the choices for the widget. To make things work. I overrode the ""get_context"" method as follows.

{{{
class AdminTagsWidget(FilteredSelectMultiple):
    def get_context(self, name, value, attrs):
        self.choices = self.is_stacked
        self.is_stacked = False
        return super().get_context(name, value, attrs)
}}}

Somewhere things are getting switched up when choices are passed into the widget. I don't know if this is the same for Django 2.0 or not. We are presently upgrading to python 3, and that is when the problem surfaced.



"	Bug	new	Forms	1.11	Normal		forms widgets multiple select		Unreviewed	0	0	0	0	0	0
