ojuso-map/apps/map/migrations/0069_remove_null_from_text_fields.py

79 lines
2.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-22 17:43
from __future__ import unicode_literals
import multiselectfield.db.fields
2019-08-19 21:53:34 +00:00
from django.db import migrations
from django.db import models
string_fields = [
2019-08-19 21:37:32 +00:00
"additional_technical_details",
"associated_infrastructure",
"biomass_detail",
"community_voices",
"contractor_or_supplier_of_technology",
"direct_comms",
"entry_name",
"full_description",
"generation_equipment_supplier",
"generation_technology",
"generation_technology_other",
"identified_partnerships",
"isolated_or_widespread",
"key_actors_involved",
"land_ownership",
"land_ownership_details",
"media_coverage_independent",
"media_coverage_mainstream",
"minerals_or_commodities",
"minerals_or_commodities_other",
"name_of_territory_or_area",
"negative_case_reasons",
"negative_case_reasons_other",
"negative_socioenvironmental_impacts",
"obstacles_and_hindrances",
"positive_case_type",
"potential_partnerships",
"power_technology",
"power_technology_other",
"project_status",
"project_status_detail",
"projected_production_of_commodities",
"sector_of_economy",
"size_of_concessions",
"social_media_links",
"socioeconomic_benefits",
"type_of_ecosystem",
"type_of_extraction",
"use_in_energy_economy",
"use_in_energy_economy_other",
"video_caption",
"video_credit",
"when_did_organising_start",
"who_has_been_involved",
]
def remove_nulls(apps, schema_editor):
# We can't import the Person model directly as it may be a newer
# version than this migration expects. We use the historical version.
2019-08-19 21:37:32 +00:00
CaseStudy = apps.get_model("map", "CaseStudy")
for study in CaseStudy.objects.all():
for field in string_fields:
if getattr(study, field) == None:
2019-08-19 21:37:32 +00:00
setattr(study, field, "")
try:
study.save()
except:
2019-08-19 21:37:32 +00:00
from pdb import set_trace
2019-08-19 21:37:32 +00:00
set_trace()
class Migration(migrations.Migration):
2019-08-19 21:37:32 +00:00
dependencies = [("map", "0068_casestudydraft_created")]
2019-08-19 21:37:32 +00:00
operations = [migrations.RunPython(remove_nulls, migrations.RunPython.noop)]