django-multiselectfield icon indicating copy to clipboard operation
django-multiselectfield copied to clipboard

Support for readonly fields

Open filipefigcorreia opened this issue 10 years ago • 3 comments

When making a MultiSelectField readonly (e.g., via de readonly_fields attribute), it gets rendered in the admin as a repr() of a python list. Would be great to make it a little more user-friendly.

filipefigcorreia avatar Nov 21 '14 12:11 filipefigcorreia

This can be worked around by using get_FIELDNAME_display in the readonly_fields list (though as a side-effect, it will always appear at the bottom of the form, unless you want to muck around with overriding get_fields and similar on the ModelAdmin class). However, the label for the field will be broken. I'll put through a pull request shortly that fixes the label issue; it's probably a change that will come in handy for a future proper fix as well.

Aramgutang avatar Feb 08 '17 06:02 Aramgutang

Can you explain a little bit more how you think this should be rendered when its a readonly field? I adjusted how the field is displayed in commit 01dcad2 (currently awaiting testing in the master branch) and that may be more to your liking. See this comment for how it renders in the admin list_display and list_filter now.

The only other good way I can think to display this is as a list of disabled checkboxes of all choices where the checkbox is checked for choices in the list and unchecked if not. Example:

Possible choices are Beethoven, Bach, and Chopin, only Bach and Chopin are selected:

  • [ ] Beethoven
  • [x] Bach
  • [x] Chopin

blag avatar Feb 28 '17 08:02 blag

This would be really cool to have 👍

gabn88 avatar May 01 '17 12:05 gabn88