Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###Dump fixture data to be loaded###
- ```python manage.py dumpdata --format=json your_app > /app/path/your_app/fixtures/fixture_data_file.json```
- ###Create an empty migration file###
- ```python manage.py makemigrations --empty your_app```
- ###Edit the newly created migration file for your_app###
- ```
- # -*- coding: utf-8 -*-
- from __future__ import unicode_literals
- from django.db import models, migrations
- from django.core.management import call_command
- fixture = 'fixture_data_file'
- def load_fixture_data(apps, schema_editor):
- """load in the 'your_fixture_data_file' to the database"""
- call_command('loaddata', fixture, app_label='your_app')
- def unload_fixture_data(apps, schema_editor):
- """Brutally deleting all entries for this model"""
- YourModel = apps.get_model("your_app", "YourModel")
- YourModel.objects.all().delete()
- class Migration(migrations.Migration):
- dependencies = [
- ('your_app', '0002_auto_20150418_1326'),
- ]
- operations = [
- migrations.RunPython(load_fixture_data, reverse_code=unload_fixture_data),
- ]
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement