From 794bd415463d568791a5f853dea27ab5eb77f9f4 Mon Sep 17 00:00:00 2001 From: Jian Dai Date: Thu, 20 Feb 2020 13:53:32 +0800 Subject: [PATCH] Optimize multiselectfield to_python method. (#106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- multiselectfield/db/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/multiselectfield/db/fields.py b/multiselectfield/db/fields.py index f0eb216..6e94bd2 100644 --- a/multiselectfield/db/fields.py +++ b/multiselectfield/db/fields.py @@ -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, [])