Created
December 16, 2015 18:41
-
-
Save kiote/fca7ea351e0c2a016390 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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