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.0.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.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jessilver_django_seed-2.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 546d6ec5573310aad5c0bdbccf1aed2d233b95c72741ba6b564f43220b715277
MD5 48d2e332bfb4ca9c37164d2da42cc479
BLAKE2b-256 0d12c2163c64fd066c4cfdc106dfb8abe36461c4813c633c87caef2bdc07820c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jessilver_django_seed-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8990f73f4c2374eb066239a14cd4fded800c549d8adcf2fefd3cce8e06c777a6
MD5 cc2f5738699cea130198106634034bfa
BLAKE2b-256 c1b99ef87fd80f3176c36b56a050e9eeaaa93395498679cc0ca2ef621001372b

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