Optimize multiselectfield to_python method. (#106)

* 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
This commit is contained in:
Jian Dai 2020-02-20 13:53:32 +08:00 committed by GitHub
parent 9e44443275
commit 794bd41546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -152,7 +152,8 @@ class MultiSelectField(models.CharField):
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, [])