A few extra management tools to handle fixtures.
Project description
This package requires:
Python 2.6
Django
Installation
You can get fixture-magic from pypi with:
pip install django-fixture-magic
The development version can be installed with:
pip install -e git://github.com/davedash/django-fixture-magic#egg=django_fixture_magic
fixture-magic adds two commands to manage.py therefore you should add it to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = ( ... 'fixture_magic', ... )
Usage
There are four commands. dump_object returns the json representation of a specific object as well as all its dependencies (as defined by ForeignKeys).
./manage.py dump_object APP.MODEL PK1 PK2 PK3 … > my_new_fixture.json
You can now safely load my_new_fixture.json in a test without foreign key i errors.
The second command is merge_fixtures. This command takes several fixture files and does a simple de-dupe operation (based on model and pk) and returns a clean json file. This is helpful if you have multiple json fixtures that might have redundant data.
./manage.py merge_fixtures fixture1.json fixture2.json fixture3.json … > all_my_fixtures.json
The third command is reorder_fixtures. This command takes a single file and several model names (in app.model format as they are specified in fixture files). This reorders your fixtures so the models you specifiy first show up in the fixture first. This is helpful if you tend to get foreign-key errors when loading models.
./manage.py reorder_fixtures fixture.json APP1.MODEL1 APP2.MODEL2 … > ordered_fixture.json
Unspecified models will be appended to the end.
The fourth command is custom_dump. This reads a setting CUSTOM_DUMPS:
## Fixture Magic CUSTOM_DUMPS = { 'addon': { # ./manage.py custom_dump addon id 'primary': 'addons.addon', # This is our reference model. 'dependents': [ # These are items we wish to dump. 'current_version', # Magic turns this into current_version.files.all()[0]. 'current_version.files.all.0', ], 'order': ('app1.model1', 'app2.model2',), # stuff gets sorted 'excludes': { 'app1.model1': ('fields', 'to', 'hide',), }, } }
It runs the equivalent of dump_object on the dependents (which in turn pick up the primary object). The JSON dumps are then merged together. Very handy for dumping multi-dependent objects. Everything is reordered and excludes are filtered out.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-fixture-magic-0.0.3.tar.gz
.
File metadata
- Download URL: django-fixture-magic-0.0.3.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cd4ce6e5639b0f4a02f22ace6e8a5a942c9b5e1079126264ea34c01460cce1a |
|
MD5 | 91a4ba4f95d1a5335e7c5e3cc136416e |
|
BLAKE2b-256 | a827b6f9e59539a6902f837ab41209369aa4bf2192d28ca929d4238fa0fa371d |