Skip to content

Instantly share code, notes, and snippets.

@kiote
Created December 16, 2015 18:41
Show Gist options
  • Save kiote/fca7ea351e0c2a016390 to your computer and use it in GitHub Desktop.
Save kiote/fca7ea351e0c2a016390 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
from cities.models import Country
def add_country_connection(apps, schema_editor):
ExtraCountry = apps.get_model("extra_countries", "ExtraCountry")
for country in Country.objects.all():
print("seeding country connection for county: %s" % country.name)
ex = ExtraCountry(code=country.code3,
country_id=country.pk)
ex.save()
def reverse_data(apps, schema_editor):
ExtraCountry = apps.get_model("extra_countries", "ExtraCountry")
ExtraCountry.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('extra_countries', '0001_initial')
]
operations = [
migrations.RunPython(add_country_connection, reverse_data)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment