Skip to content

Commit

Permalink
Optimize multiselectfield to_python method. (#106)
Browse files Browse the repository at this point in the history
* Optimize multiselectfield to_python method.

When using  with django import export plugin, optimize these 2 things:
1. User usally input a " " after ",",  optimize the parse method, trim it.
2. User also can input "," instead of ",",  for a better user experience.

* Update fields.py
  • Loading branch information
daimon99 authored Feb 20, 2020
1 parent 9e44443 commit 794bd41
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion multiselectfield/db/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def to_python(self, value):
if isinstance(value, list):
return value
elif isinstance(value, string_type):
return MSFList(choices, value.split(','))
value_list = map(lambda x: x.strip(), value.replace(u',', ',').split(','))
return MSFList(choices, value_list)
elif isinstance(value, (set, dict)):
return MSFList(choices, list(value))
return MSFList(choices, [])
Expand Down

0 comments on commit 794bd41

Please sign in to comment.