Refactor get_zone_pk_mapping method

This commit is contained in:
Dana Lambert 2021-11-08 10:53:38 +13:00
parent 316df45784
commit 29b9051773
2 changed files with 3 additions and 7 deletions

View file

@ -57,7 +57,7 @@ ECO_REGION_PK_MAPPING = get_pk_mapping(EcologicalRegion)
SOIL_ORDER_PK_MAPPING = get_pk_mapping(SoilOrder) SOIL_ORDER_PK_MAPPING = get_pk_mapping(SoilOrder)
SOIL_VARIANT_PK_MAPPING = get_pk_mapping(SoilVariant) SOIL_VARIANT_PK_MAPPING = get_pk_mapping(SoilVariant)
TOLERANCE_PK_MAPPING = get_pk_mapping(ToleranceLevel, "level") 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 and corresponding value to column index mappings
SPREADSHEET = get_spreadsheet(DATA_DIR_PATH, SPREADSHEET_FILENAME) SPREADSHEET = get_spreadsheet(DATA_DIR_PATH, SPREADSHEET_FILENAME)

View file

@ -12,14 +12,10 @@ def get_pk_mapping(object, mapping_key="name"):
return pk_mapping 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. """ Maps the string instance (unique) of a zone to its corresponding primary key.
""" """
zone_pk_mapping = {} return {str(instance): instance.pk for instance in Zone.objects.all()}
for instance in zone_model.objects.all():
zone_pk_mapping[str(instance)] = instance.pk
return zone_pk_mapping
def get_col_mappings(sheet, start_col, stop_col, row_index): def get_col_mappings(sheet, start_col, stop_col, row_index):