Skip to main content

A Django app to generate and seed database models with realistic test data using Faker. Includes features for automatic backup of deleted instances and detailed log entries for instance mutations, ensuring data safety and comprehensive change tracking.

Project description

Django Data Seed is a powerful Django application designed to simplify the process of populating your database with realistic test data. By leveraging the Faker library, this package allows you to effortlessly generate random data for your models using a single command via manage.py. It is especially beneficial for developers who need diverse datasets to ensure comprehensive test coverage and data integrity.

Features

  • Comprehensive Data Generation: Generate random, realistic data for a wide range of Django model fields.
  • Simple Seeding Process: Seed your database models with randomly generated data using a single command.
  • Complex Relationship Handling: Seamlessly manage complex relationships between different models.
  • Data Backup and Restoration: Automatically back up deleted instances and restore them when needed.
  • Detailed Log Entries: Maintain detailed log entries for instance mutations, allowing you to track changes over time.

New in Version

Data Backup Feature

Ensure data safety with the new automatic backup feature. When an instance is deleted, it is stored in the DjangoSeedDataBackUpModel. This feature can be enabled in your settings:

ENABLE_DJANGO_DATA_SEED_AUTO_BACKUP = True

To disable, set the variable to False or remove it entirely. You can restore deleted instances from the Django admin panel by selecting the deleted instance and choosing the "Restore data" option.

Log Entries for Instance Mutations

Track every change made to your instances with detailed log entries. This feature stores both pre- and post-mutation states of an instance. Enable this feature by adding the following setting:

ENABLE_DJANGO_DATA_SEED_AUTO_LOG_ENTRY = True

Restore any instance to a previous state from the admin panel by selecting the log entry and choosing the "Restore data" option.

Authentication Configurations

To record the user responsible for deletions or mutations, add the middleware to your settings.py:

MIDDLEWARE = [
    # other middleware's
    ...
    "django_data_seed.middleware.CurrentUserMiddleware"
]

If the default middleware does not suit your authentication system, create a custom middleware:

from django_data_seed.utils.get_user import set_current_user

class YourCustomMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        set_current_user(request.user)
        response = self.get_response(request)
        return response

Field Generation Updates

  • Now supports choices in CharField and JsonField, allowing for more realistic and varied data generation.

Enhanced Command Options

  • Target Specific Models: You can now seed data for a single model using the django-app argument in the manage.py command:

    python manage.py seeddata --django-app model_name
    

Installation

To install django-data-seed, use pip:

pip install django-data-seed

Add django_data_seed to your INSTALLED_APPS in your Django settings:

INSTALLED_APPS = [
    ...
    'django_data_seed',
    ...
]

After adding django_data_seed to your INSTALLED_APPS, run the following command to apply migrations:

python3 manage.py migrate

Dependencies

The following dependencies are required and will be installed automatically with django-data-seed:

  • Django (>=3.2)
  • Faker (>=8.0.0)
  • colorama (>=0.4.6)

You can also install them manually:

pip install Django>=3.2
pip install Faker>=8.0.0
pip install colorama>=0.4.6

Usage

To seed your database, use the seeddata command:

python3 manage.py seeddata

To specify the number of instances per model:

python3 manage.py seeddata --no-of-objects 100

To seed data for a specific Django app:

python3 manage.py seeddata --django-app app_name

To seed data for a specific model:

python3 manage.py seeddata --django-model model_name

Supported Versions

Django Versions

  • Django 3.2
  • Django 4.0
  • Django 4.1

Python Versions

  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10

Operating Systems

  • Windows
  • macOS
  • Linux

Databases

  • MySQL
  • PostgreSQL
  • SQLite

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Support

For any issues or questions, open an issue on the GitHub repository.

Author

Rohith Baggam

LinkedIn Profile


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-data-seed-0.4.2.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

django_data_seed-0.4.2-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file django-data-seed-0.4.2.tar.gz.

File metadata

  • Download URL: django-data-seed-0.4.2.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for django-data-seed-0.4.2.tar.gz
Algorithm Hash digest
SHA256 d93be397ee7013123f66521fcf6d7d2a0143bed693f05661aba313ac2c8356d2
MD5 bbee641b64a8a61bd8e94f6dbdea584b
BLAKE2b-256 f01669817b0a316ad1a2a42c9e495396e81ced0d604b10197e89842c51879598

See more details on using hashes here.

File details

Details for the file django_data_seed-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_data_seed-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 15ac7e6c5d00271510f50deed49526dc5610dc98359163caeb93eb11d1952c92
MD5 7f33048ea2b62098a6b40ade35390882
BLAKE2b-256 6138bdcf8dfb3c325ff01fda16a6cfde9392f1d62ddf0d89615012820be67d80

See more details on using hashes here.

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