Skip to content

Commit 3ce1a35

Browse files
committed
Added SIMPLE_IMPORT_LAZY_CHOICES_STRIP setting (disabled by default) which will strip leading/trailing whitespace from cell value before comparison. Updated README.
1 parent fcdaaf6 commit 3ce1a35

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ SIMPLE_IMPORT_LAZY_CHOICES: Default True. If enabled simple_import will look up
5555

5656
If the spreadsheet value is "Monday" it will set the database value to "M."
5757

58+
SIMPLE_IMPORT_LAZY_CHOICES_STRIP: Default False. If enabled, simple_import will trip leading/trailing whitespace
59+
from the cell's value before checking for a match. Only relevant when SIMPLE_IMPORT_LAZY_CHOICES is also enabled.
60+
5861
If you need any help, we do consulting and custom development. Just email us at david at burkesoftware.com.
5962

6063

simple_import/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ def set_field_from_cell(import_log, new_object, header_row_field_name, cell):
294294
related_object = related_model.objects.get(**{related_field_name:cell})
295295
setattr(new_object, header_row_field_name, related_object)
296296
elif field.choices and getattr(settings, 'SIMPLE_IMPORT_LAZY_CHOICES', True):
297+
# Trim leading and trailing whitespace from cell values
298+
if getattr(settings, 'SIMPLE_IMPORT_LAZY_CHOICES_STRIP', False):
299+
cell = cell.strip()
297300
# Prefer database values over choices lookup
298301
database_values, verbose_values = zip(*field.choices)
299302
if cell in database_values:

0 commit comments

Comments
 (0)