Don't be stupid, and load fixtures in a smart way
Project description
Django Smart Fixtures
DON'T BE STUPID, AND LOAD FIXTURES IN A SMART WAY!
Purpose
This Django package provides load_fixtures
management command that allows you
to load fixtures in a more convenient way. It uses Django's built-in
loaddata
command under the hood. Unlike loaddata
, load_fixtures
allows you
to load multiple fixtures without passing their labels to the command. The only
thing you need to do is to configure the fixtures to load in the settings.
Ah, yes... and it also allows you to easily upload media files (images,
files, etc.) from the fixtures.
Installation
pip install django-smart-fixtures
Add django_smart_fixtures
to your INSTALLED_APPS
:
INSTALLED_APPS = [
...
'django_smart_fixtures',
...
]
Configuration
Let's say you have the following fixtures:
my_app/
└──fixtures/
├── fixtures1.yaml
├── fixtures2.yaml
└── images/
├── image1.jpg
└── image2.jpg
my_other_app/
└──fixtures/
├── fixtures3.yaml
└── files/
├── file1.txt
└── file2.txt
You can configure the fixtures to load in the settings:
# settings.py
FIXTURES = {
'labels': [
'fixtures1',
'fixtures2',
'fixtures3',
],
'images_dirs': [
{
'src': BASE_DIR / 'my_app' / 'fixtures' / 'images',
'dest': BASE_DIR / 'media' / 'my_app' / 'images',
},
{
'src': BASE_DIR / 'my_other_app' / 'fixtures' / 'files',
'dest': BASE_DIR / 'media' / 'my_other_app' / 'files',
},
],
}
Then you can load all these fixtures by running:
python manage.py load_fixtures
This will load all the fixtures defined in fixtures1.yaml
, fixtures2.yaml
,
and fixtures3.yaml
. It will also copy all files from images
and files
folders to the media folder.
NOTE: Using the above example, files from images
will end up in the
media/my_app/images
folder, and files from files
will end up in the
media/my_other_app/files
folder. Relative to media root directory, paths of
copied files will be:
my_app/images/image1.jpg
my_app/images/image2.jpg
my_other_app/files/file1.txt
my_other_app/files/file2.txt
This is exactly how paths should be defined in the fixture files:
- model: my_app.MyModel
pk: 1
fields:
image: my_app/images/image1.jpg
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_smart_fixtures-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9592929056f88580029ac1913f6d6bf6f01e69986fa3897e4bd03473d96b4aaf |
|
MD5 | 6d190cf8442b552dfa2e4c493fa7124e |
|
BLAKE2b-256 | 59218ea8d8b130a6db4bcd5a9ca71bf9fab3aba77b30ac09c5c5e3f29539be22 |
Hashes for django_smart_fixtures-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 676057023072a42f1eeb7960059320e11ae816a7a3a3f158df1bb4cd4a388c34 |
|
MD5 | 01f5e491356a466ba12996d8b93e3f67 |
|
BLAKE2b-256 | b6a340eee753830826abd53c71501e9d0089dcdcf4aec3969e8e724b812f363b |