Skip to main content

A library to facilitate the creation of fake data (seeds) in Django projects.

Project description

jessilver_django_seed

A library to facilitate the creation of fake data (seeds) in Django projects, with custom management commands, modularization, selective seeder execution, and easy integration.

Installation

Install from PyPI:

pip install jessilver_django_seed

Requirements

  • Python 3.7+
  • Django >= 3.2

Configuration

  1. Add 'jessilver_django_seed' to your INSTALLED_APPS.
  2. In your settings.py, define:
    SEEDER_APPS = [
        'your_app_name',
        # ...other apps
    ]
    
    Each app directory should contain a seeders/ folder with your seeder files.

Seeder Structure

Create Python files in the seeders/ folder of your app. Example:

# myapp/seeders/UserSeeder.py
from jessilver_django_seed.seeders.BaseSeeder import BaseSeeder
from myapp.models import User

class UserSeeder(BaseSeeder):
    @property
    def seeder_name(self):
        return "UserSeeder"
    def seed(self):
        for i in range(10):
            User.objects.create(username=f'user{i}')
        self.succes("10 users created!")

Seed Command

Run all seeders:

python manage.py seed

Selective Execution

Run only specific seeders:

python manage.py seed --only UserSeeder,ProductSeeder

Seeder Creation via CLI

You can create a new seeder file automatically using the management command:

python manage.py seed --create UserSeeder --app myapp
  • This will create a file myapp/seeders/UserSeeder.py with a template class if it does not already exist.
  • If the app is not listed in SEEDER_APPS in your settings.py, it will be added automatically.
  • The command validates the seeder class name and ensures no duplicates.

How it works

  • The library looks for all apps listed in SEEDER_APPS.
  • For each app, it dynamically loads all Python files in the seeders/ folder.
  • It searches for classes ending with Seeder (exemple UserSeeder).

Seed Command

  • Argument --only: Runs only the seeders whose class names are provided.
  • Interactive confirmation before execution.
  • Status messages and summary at the end.

Seeder Execution Order

Seeders are loaded and executed in alphabetical order based on their filename. You can control the execution order by naming your seeder files with numeric or alphabetical prefixes, e.g.:

01_UserSeeder.py
02_ProductSeeder.py

This ensures that seeders run in the desired sequence.

Compatibility

All file and directory operations use Python's os.path.join and standard library functions, ensuring compatibility across Linux, Windows, and MacOS. No hardcoded path separators are used.

Examples

Product Seeder

# myapp/seeders/ProductSeeder.py
from jessilver_django_seed.seeders.BaseSeeder import BaseSeeder
from myapp.models import Product

class ProductSeeder(BaseSeeder):
    @property
    def seeder_name(self):
        return "ProductSeeder"
    def seed(self):
        for i in range(5):
            Product.objects.create(name=f'Product {i}')
        self.succes("5 products created!")

Running only the UserSeeder

python manage.py seed --only UserSeeder

Contributing

Pull requests are welcome! Open issues for suggestions or problems.

License

MIT

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

jessilver_django_seed-2.0.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

jessilver_django_seed-2.0.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file jessilver_django_seed-2.0.1.tar.gz.

File metadata

  • Download URL: jessilver_django_seed-2.0.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for jessilver_django_seed-2.0.1.tar.gz
Algorithm Hash digest
SHA256 5150d9dbf68743a89333da1e2a1a9847135211cc7207a9d6496490fa7303e0f3
MD5 c2f1a9583d89254455b8f07474dd4488
BLAKE2b-256 7375f3ac838b55c3d04e0bb65277a47064b0202cf2fe98a027692aacf97f807e

See more details on using hashes here.

File details

Details for the file jessilver_django_seed-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jessilver_django_seed-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8199d0d6e153e007d8cbfdca45220329ddbfe5c2bb1d39f8ab23014f7d7a26c0
MD5 e405070cd024591219bad4c4312171e2
BLAKE2b-256 d5439aa6f270880a46c0b7f3d9323b97af41fe038ec2f4f64f280ef4ddde485d

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