django-data-seed 0.4.2

Creator: danarutscher

Last updated:

Add to Cart

Description:

djangodataseed 0.4.2

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

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.