From eae6a04344358f51b56ab3dbd433dd5146d9bebb Mon Sep 17 00:00:00 2001 From: Julio Cesar <juliocesarrodriguezcruz@gmail.com> Date: Sun, 5 Jul 2015 05:19:42 -0500 Subject: [PATCH] Autoload fixtures. --- MANIFEST.in | 1 + README.rst | 3 +-- world_regions/migrations/0001_initial.py | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 9557406..b8f458b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,4 +3,5 @@ include README.rst recursive-include world_regions/static * recursive-include world_regions/fixtures * recursive-include world_regions/templates * +recursive-include world_regions/migrations * recursive-include docs * \ No newline at end of file diff --git a/README.rst b/README.rst index 45f8f4e..c11109e 100644 --- a/README.rst +++ b/README.rst @@ -15,7 +15,6 @@ Installation 1. ``pip install django-world-regions`` 2. Add ``world_regions`` to ``INSTALLED_APPS`` 3. ``python manage.py migrate`` -4. ``python manage.py loaddata fixtures/initial_data.json`` Usage ===== @@ -24,7 +23,7 @@ Usage from world_regions.models import Region - region = Region.objects.get(countries_country='US') + region = Region.objects.get(countries__country='US') print region.name .. _Django Countries: https://github.com/SmileyChris/django-countries \ No newline at end of file diff --git a/world_regions/migrations/0001_initial.py b/world_regions/migrations/0001_initial.py index 5d26535..7a02810 100644 --- a/world_regions/migrations/0001_initial.py +++ b/world_regions/migrations/0001_initial.py @@ -1,10 +1,14 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals - +from django.core.management import call_command from django.db import models, migrations import django_countries.fields +def load_data_in_fixtures(apps, schema_editor): + call_command('loaddata', 'initial_data', app_label='world_regions') + + class Migration(migrations.Migration): dependencies = [ @@ -24,7 +28,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('country', django_countries.fields.CountryField(unique=True, max_length=2)), - ('region', models.ForeignKey(related_name='countries', to='simple_regions.Region')), + ('region', models.ForeignKey(related_name='countries', to='world_regions.Region')), ], ), + migrations.RunPython(load_data_in_fixtures), ]