Help with FilteredSelectMultiple

325 views
Skip to first unread message

Ike

unread,
Jul 21, 2018, 10:35:32 AM7/21/18
to Django users
Good day everyone, I've been stuck with a problem I am having and I can't find any help online. 

I am trying to assign staffs to a particular role (Moderator, Instructor,....) using the FilteredSelectMultiple widget (Similar to Django Admin's assign permissions/groups). I have managed to display that widget on my site already (Each role has its own FSM widget where you select the staffs) but I'm not sure how to:
  • Associate the widget to a role
    • I've managed to display the FilteredSelectMultiple widgets on my site, that part is true. However, I'm not sure how to associate that widget to its own role. The items in the FSM widget are the staff's name, so role is actually empty.
  • How to save into Database
    • When I assign an item to the Chosen box, I want that to be saved to the database. If I remove, I want it to be deleted from the database
    • I'm currently using a FormView and I'm not sure how to do this (Not good with Function based views and am more comfortable with CBVs)
  • How do I have the chosen elements be displayed on the Chosen box the next time a user revisits the page?




Ike

unread,
Jul 21, 2018, 11:38:46 AM7/21/18
to Django users
Update: forms.py and designations.html has been updated.
This was the only way I could think of for associating the roles to the widget

Melvyn Sopacua

unread,
Jul 21, 2018, 1:53:34 PM7/21/18
to django...@googlegroups.com
On zaterdag 21 juli 2018 14:38:11 CEST Ike wrote:
> Good day everyone, I've been stuck with a problem I am having and I can't
> find any help online.

Even though you've done much effort to make a good problem description, you're
still making us do a lot of work before we can diagnose your issue:

- imports are missing from code
- used modules (requirements.txt) are missing (where is FilteredSelectWidget
from)
- get_success_url isn't properly indented
- the entire save code is missing (form_valid is not implemented)

It's much easier to either open source your project or setup an test project
that actually works and has either a setup.py or requirements.txt, since this
touches on several issues.

It's also completely unclear why you think you have to use function based
views.

If what you really want is to have a save done as soon as a name enters or is
removed from the box on the right, then the scope just increased tremendously
and you need to grow frontend skills.

Otherwise, things just work out of the box (upon form submission, you can call
form.save() in Formview.is_valid()) or the widget isn't worth it's salt.
--
Melvyn Sopacua

Ike

unread,
Jul 23, 2018, 11:29:21 PM7/23/18
to Django users
Hi Melvyn, 

Sorry for the late reply, also this is my first post here so I'm not really sure what's needed. FilteredSelectMultiple is a django admin widget so it isn't in the requirements.txt. 

I have managed to save to the database already via ajax request. However, I am unable to have the chosen items be shown the next time the user revisits the page. Appending options via jquery/javascript doesn't work. 

Attached are all the codes and requirements.txt: https://gist.github.com/Yggralith0/054f4bd1752a608ef3f96ce01bd8fe5c

Yours sincerely,
Ike
Reply all
Reply to author
Forward
0 new messages