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

79 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-22 17:43
from __future__ import unicode_literals
from django.db import migrations, models
import multiselectfield.db.fields
from apps.map.models import CaseStudy
string_fields = [
'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.
study = apps.get_model('map', 'CaseStudy')
for study in CaseStudy.objects.all():
for field in string_fields:
if getattr(study, field) == None:
setattr(study, field, '')
study.save()
class Migration(migrations.Migration):
dependencies = [
('map', '0068_casestudydraft_created'),
]
operations = [
migrations.RunPython(remove_nulls),
]