Opened 6 years ago

Last modified 6 years ago

#29742 closed Bug

Problem overriding the FilteredSelectMultiple widget — at Initial Version

Reported by: Bryant Glisson Owned by: nobody
Component: Forms Version: 1.11
Severity: Normal Keywords: forms widgets multiple select
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top