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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file django-fixtures-command-0.1.0.tar.gz.

File metadata

  • Download URL: django-fixtures-command-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for django-fixtures-command-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3dbd5f25137d0b6eb671b39d68e7d6e22f4b2375eb4283cc55a5b60ba504a189
MD5 0c43c718c30d65ac9ec04220a1b24228
BLAKE2b-256 7742553f2f11a99499c9fa00b342d640c66e84e5ffbd4fa4041aedce668d8eb9

See more details on using hashes here.

File details

Details for the file django_fixtures_command-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_fixtures_command-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.0

File hashes

Hashes for django_fixtures_command-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7675ea1eaeadd207cd9b721d9f7aa6f61f0b8b2067bfd8a48d3d5f0fc9f46b1e
MD5 aa355a83b7434824f71b1c912b070d67
BLAKE2b-256 99d55504438846b44cf17b067c5d687aa2df0b993b7226cee336d5ea466d52c5

See more details on using hashes here.

Supported by

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