Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from __future__ import unicode_literals
- import os
- from django.db import models, migrations
- from django.core import serializers
- fixture_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
- '../fixtures'))
- fixture_filename = 'initial_data.json'
- def load_fixture(apps, schema_editor):
- fixture_file = os.path.join(fixture_dir, fixture_filename)
- with open(fixture_file, 'rb') as fixture:
- objects = serializers.deserialize('json', fixture,
- ignorenonexistent=True)
- for obj in objects:
- obj.save()
- def unload_fixture(apps, schema_editor):
- MyModel = apps.get_model("book", "Genre")
- MyModel.objects.all().delete()
- class Migration(migrations.Migration):
- dependencies = [
- ('book', '0001_initial'),
- ]
- operations = [
- migrations.RunPython(load_fixture, reverse_code=unload_fixture),
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement