Created
August 14, 2023 01:46
-
-
Save monkut/906bdbb62c184d1d46afeff1757af5f1 to your computer and use it in GitHub Desktop.
Django admin widget to allow proper multiple selection of selected checkbox entries for CheckboxSelectMultiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArrayFieldCheckboxSelectMultiple(CheckboxSelectMultiple): | |
"""A CheckboxSelectMultiple widget for use with ArrayField which fixes the Multiple items not selected issue""" | |
def format_value(self, value): | |
"""Return selected values as a list.""" | |
if value is None and self.allow_multiple_selected: | |
return [] | |
elif self.allow_multiple_selected: | |
value = [v for v in value.split(",")] | |
if not isinstance(value, (tuple, list)): | |
value = [value] | |
results = [str(v) if v is not None else "" for v in value] | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment