Skip to content

Commit

Permalink
Autoload fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarcruz committed Jul 5, 2015
1 parent a6f1a6d commit eae6a04
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand All @@ -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
9 changes: 7 additions & 2 deletions world_regions/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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),
]

0 comments on commit eae6a04

Please sign in to comment.