Replace all Range with MountainRange in import script

This commit is contained in:
PCoder 2021-11-29 08:59:07 +05:30
parent f828ce5a6e
commit f1eaedbd14

View file

@ -384,11 +384,11 @@ class Command(BaseCommand):
# We have loaded the range model already and we are attempting to construct the mother_range # We have loaded the range model already and we are attempting to construct the mother_range
# relationship # relationship
try: try:
this_range = Range.objects.get(id=int(row[0])) this_range = MountainRange.objects.get(id=int(row[0]))
r = Range.objects.get(id=int(row[5])) # default Range which exists already r = MountainRange.objects.get(id=int(row[5])) # default Range which exists already
this_range.mother_range = r this_range.mother_range = r
this_range.save() this_range.save()
except Range.DoesNotExist as dne: except MountainRange.DoesNotExist as dne:
print("this range = %s, mother range --> %s" % (row[0], row[5])) print("this range = %s, mother range --> %s" % (row[0], row[5]))
print(str(dne)) print(str(dne))
error_row_count += 1 error_row_count += 1
@ -416,7 +416,7 @@ def handle_object_dict(object_dict, model_name):
for i in ['PEGASuS_Check_map_with_author', 'gloria', 'gnomo', 'lter', 'ltser', 'miren', 'team', 'inventory']: for i in ['PEGASuS_Check_map_with_author', 'gloria', 'gnomo', 'lter', 'ltser', 'miren', 'team', 'inventory']:
if i in object_dict: if i in object_dict:
object_dict[i] = True if object_dict[i].lower().strip() == 'true' else False object_dict[i] = True if object_dict[i].lower().strip() == 'true' else False
if model_name == 'Range': if model_name == 'MountainRange':
# Reinstate range_name key # Reinstate range_name key
object_dict['range_name'] = object_dict['range_name_id'] object_dict['range_name'] = object_dict['range_name_id']
object_dict.pop('range_name_id') object_dict.pop('range_name_id')
@ -430,8 +430,8 @@ def handle_object_dict(object_dict, model_name):
if object_dict['mother_range'] == '': if object_dict['mother_range'] == '':
object_dict['mother_range'] = 0 object_dict['mother_range'] = 0
try: try:
object_dict['mother_range'] = Range.objects.get(id=0) # default Range which exists already object_dict['mother_range'] = MountainRange.objects.get(id=0) # default Range which exists already
except Range.DoesNotExist as dne: except MountainRange.DoesNotExist as dne:
print(str(dne)) print(str(dne))
for i in ['checked']: for i in ['checked']:
if i in object_dict: if i in object_dict: