Simple Django command that helps to organize your fixtures
Project description
django-fixtures-command
Simple Django command that helps to organize your fixtures.
Usage
Add fixtures.py
files anywhere you want in your Django project. Put there the functions that handle fake data for development purposes.
The function must have fill_
or flush_
prefix and must be defined in the fixtures.py
file to be found by ./manage.py fixtures
command.
Commands
Display all available fixtures along with their docstrings:
./manage.py fixtures --all
Fill the database with fake data:
./manage.py fixtures fill <fixture_name>
Flush data from the database:
./manage.py fixtures flush <fixture_name>
Example
It is convenient to use some tool to generate fake data for fixtures like the factory_boy
library.
def fill_profiles():
"""Fill the database with fake user profiles."""
inactive_profile = ProfileFactory.create(
user__password=EXAMPLE_PASSWORD, user__is_active=False,
)
active_profile = ProfileFactory.create(user__password=EXAMPLE_PASSWORD, user__is_active=True)
admin_profile = ProfileFactory.create(
user__password=EXAMPLE_PASSWORD, user__is_superuser=True, user__is_staff=True,
)
print('Inactive profile:', inactive_profile.user.email, 'password:', EXAMPLE_PASSWORD)
print('Active profile:', active_profile.user.email, 'password:', EXAMPLE_PASSWORD)
print('Admin profile:', admin_profile.user.email, 'password:', EXAMPLE_PASSWORD)
def flush_profiles():
"""Remove all user profiles."""
Profile.objects.all().delete()
Installation
Install with pip:
python -m pip install django-fixtures-command
Then add to your installed apps:
INSTALLED_APPS = [
...,
'django_fixtures_command'
]
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
Built Distribution
Hashes for django-fixtures-command-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3dbd5f25137d0b6eb671b39d68e7d6e22f4b2375eb4283cc55a5b60ba504a189 |
|
MD5 | 0c43c718c30d65ac9ec04220a1b24228 |
|
BLAKE2b-256 | 7742553f2f11a99499c9fa00b342d640c66e84e5ffbd4fa4041aedce668d8eb9 |
Hashes for django_fixtures_command-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7675ea1eaeadd207cd9b721d9f7aa6f61f0b8b2067bfd8a48d3d5f0fc9f46b1e |
|
MD5 | aa355a83b7434824f71b1c912b070d67 |
|
BLAKE2b-256 | 99d55504438846b44cf17b067c5d687aa2df0b993b7226cee336d5ea466d52c5 |