Skip to main content

Simple Django command that helps to organize your fixtures

Project description

django-fixtures-command

Actions Status

Simple Django command that helps to organize your fixtures.

Example usage of django-fixtures-command

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fixtures-command-0.1.0.tar.gz (8.4 kB view hashes)

Uploaded Source

Built Distribution

django_fixtures_command-0.1.0-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page