From 29b90517736da4ad7a9bd3f1332416ec184d1d6f Mon Sep 17 00:00:00 2001 From: Dana Lambert Date: Mon, 8 Nov 2021 10:53:38 +1300 Subject: [PATCH] Refactor get_zone_pk_mapping method --- .../api/management/commands/_spreadsheet_constants.py | 2 +- .../api/management/commands/_spreadsheet_helpers.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/backend/right_tree/api/management/commands/_spreadsheet_constants.py b/backend/right_tree/api/management/commands/_spreadsheet_constants.py index f211ebc..6ffbaa5 100644 --- a/backend/right_tree/api/management/commands/_spreadsheet_constants.py +++ b/backend/right_tree/api/management/commands/_spreadsheet_constants.py @@ -57,7 +57,7 @@ ECO_REGION_PK_MAPPING = get_pk_mapping(EcologicalRegion) SOIL_ORDER_PK_MAPPING = get_pk_mapping(SoilOrder) SOIL_VARIANT_PK_MAPPING = get_pk_mapping(SoilVariant) TOLERANCE_PK_MAPPING = get_pk_mapping(ToleranceLevel, "level") -ZONE_PK_MAPPING = get_zone_pk_mapping(Zone) +ZONE_PK_MAPPING = get_zone_pk_mapping() # Spreadsheet and corresponding value to column index mappings SPREADSHEET = get_spreadsheet(DATA_DIR_PATH, SPREADSHEET_FILENAME) diff --git a/backend/right_tree/api/management/commands/_spreadsheet_helpers.py b/backend/right_tree/api/management/commands/_spreadsheet_helpers.py index aadc167..9180da5 100644 --- a/backend/right_tree/api/management/commands/_spreadsheet_helpers.py +++ b/backend/right_tree/api/management/commands/_spreadsheet_helpers.py @@ -12,14 +12,10 @@ def get_pk_mapping(object, mapping_key="name"): return pk_mapping -def get_zone_pk_mapping(zone_model): +def get_zone_pk_mapping(): """ Maps the string instance (unique) of a zone to its corresponding primary key. """ - zone_pk_mapping = {} - for instance in zone_model.objects.all(): - zone_pk_mapping[str(instance)] = instance.pk - - return zone_pk_mapping + return {str(instance): instance.pk for instance in Zone.objects.all()} def get_col_mappings(sheet, start_col, stop_col, row_index):