Multiple Model Selectables with Initial Data Displaying "None"

39 views
Skip to first unread message

Chad Files

unread,
Apr 17, 2013, 7:36:25 AM4/17/13
to django-s...@googlegroups.com
I have several forms that use multiple selectables on the same page. They all work fine when adding new data. However, when the edit screen is loaded all of the selectables show "None". The actual data values are there, but no display values are shown. As you can imagine, this is troubling. Some of this started back with this ticket. That was related to focusing on the first field. That has been removed.

The issue appears to be related to loading the "data-selectable-url". When this issue occurs I can click on the list icon next to the selectable, refresh the page, and the items display as they are suppose to. It does not matter which selectable field I choose. Just forcing the data to load on one of them forces them all to load. As a work around I do a jquery ".get" for one of the urls in the header. It solves the problem, but is less than ideal.

In my setup I have large data sets behind my selectables (that is why I am using them). I make use of the "get_query" method in the lookups so I can filter data by user group. I also use javascript label formatting. Outside of that everything is vanilla.

Mark Lavin

unread,
Apr 17, 2013, 8:16:59 AM4/17/13
to django-s...@googlegroups.com

The first place I would look is at the form's initial data. The selectable widgets are built on top of MultiWidget which is somewhat opinionated in how it expects the data. The `decompress` method tries to handle setting the initial value in a flexible way:

https://bitbucket.org/mlavin/django-selectable/src/b674e4e36f8cdac5bfc9a29c996ff7d48a07a9e4/selectable/forms/widgets.py?at=default#cl-76

If you are using a model lookup and the initial value is a model instance it will generate the label. Otherwise it expects a single value to be the item id to grab with get_item. So taking a look at the initial data would be my first step.

Hope that gives you some direction.

Best,

Mark
Reply all
Reply to author
Forward
0 new messages