Modify load site data to be an zone update script for spreadsheet changes
This commit is contained in:
parent
d88ec0d3b1
commit
ab48059387
1 changed files with 16 additions and 7 deletions
|
@ -33,16 +33,25 @@ def load_habitat_zone_data(sheet):
|
|||
habitats.add(current_habitat)
|
||||
zones.add((current_habitat, current_zone, current_variant, current_refined_variant, col[0].column_letter))
|
||||
|
||||
for habitat in habitats:
|
||||
habitat_obj = Habitat(name=habitat)
|
||||
habitat_obj.save()
|
||||
# Create habitats - generally this is not needed for updating
|
||||
# for habitat in habitats:
|
||||
# habitat_obj = Habitat(name=habitat)
|
||||
# habitat_obj.save()
|
||||
|
||||
for habitat, zone, variant, refined_variant, col_letter in zones:
|
||||
zone_obj = Zone(name=zone, variant=variant,
|
||||
refined_variant=refined_variant, habitat=habitat, related_zone_segment=col_letter)
|
||||
|
||||
# Retrieve existing objects
|
||||
habitat_obj = Habitat.objects.get(name=habitat)
|
||||
zone_obj = Zone.objects.get(related_svg_segment=col_letter)
|
||||
|
||||
# Update fields if required
|
||||
zone_obj.name = zone
|
||||
zone_obj.variant = variant
|
||||
zone_obj.refined_variant = refined_variant
|
||||
zone_obj.habitat = habitat_obj
|
||||
|
||||
# Save the object
|
||||
zone_obj.save()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Ingests the site spreadsheet data into the database'
|
||||
|
||||
|
|
Loading…
Reference in a new issue