0002_data__add_countries.py 925 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# Converted from the original South migration 0003_add_countries.py

from django.db import migrations, models
from django_countries import countries


def create_embargo_countries(apps, schema_editor):
    """Populate the available countries with all 2-character ISO country codes. """
    country_model = apps.get_model("embargo", "Country")
    for country_code, __ in list(countries):
14
        country_model.objects.get_or_create(country=country_code)
15 16 17 18

def remove_embargo_countries(apps, schema_editor):
    """Clear all available countries. """
    country_model = apps.get_model("embargo", "Country")
19
    country_model.objects.all().delete()
20 21 22 23 24 25 26 27 28 29 30

class Migration(migrations.Migration):

    dependencies = [
        ('embargo', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(create_embargo_countries, remove_embargo_countries),
    ]