No project description provided
Project description
Django Seeding
Table of Contents
Introduction
This is a package that help developers seed thier database with real needed data instead of fil it manually
Installation
Installing using pip:
pip install django-seeding:
add 'django_seeding'
to your INSTALLED_APPS
setting:
INSTALLED_APPS = [
...
'django_seeding',
]
Usage
Let's take a look at a quick example of using django-seeding to build simples seeder to store it in the database.
django_seeding_example/models.py:
from django.db import models
class M1(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
django_seeding_example/seeders.py:
from django_seeding import seeders
from django_seeding.seeder_registry import SeederRegistry
from django_seeding_example.models import M1
# this is a fast seeder on a model aith a csv file that contains the data
@SeederRegistry.register
class M1Seeder(seeders.CSVFileModelSeeder):
id = 'M1Seeder'
priopity = 1
model = M1
csv_file_path = 'django_seeding_example/seeders_data/M1Seeder.csv'
django_seeding_example/seeders_data/M1Seeder.csv:
title,description
t1,d1
t2,d2
then the seeder can be run by three ways:
- To seed with a specific command (Recommended):
python manage.py seed
- To seed with runserver manually just add "--seed" in runserver command:
python manage.py runserver --seed
- To seed on runserver automatically just set in your project settings:
SEEDING_ON_RUNSERVER = True
Features
With django-seeding package you can:
- Use Full Implemenation for fast model seeding (bulk_create) by [ModelSeeder, CSVFileModelSeeder and JSONFileModelSeeder]
- Use Full Implemenation for slow serializer seeding one-by-one (not bulk_create) (to inject your logic in the seeder) by [SerializerSeeder, CSVFileSerializerSeeder and JSONFileSerializerSeeder]
- Use CSV file reader by pandas package
- Use JSON file reader
- write you custom seeder
- sort your seeders by the priority class-attribute
- give a specific identifiers to you seeder by id class-attribute
- limit a seeder to be applied just in the debug mode by just_debug class-attribute
- let the seeders be applied with the runserver with SEEDING_ON_RUNSERVER variable in you project settings file
- runserver with seeding with --seed (even that SEEDING_ON_RUNSERVER=False) : "python manage.py runserver --seed"
- runserver without seeding with --dont-seed (even that SEEDING_ON_RUNSERVER=True): "python manage.py runserver --dont-seed"
Contributing
If you have suggestions for how Django Seeding could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
For more, check out the Contributing Guide.
Contact
Suliman Awad - sulimanawadstudy@gmail.com - Linkedin
Project Link: https://github.com/suliman-99/django-seeding
License
MIT License
Copyright (c) 2023 Suliman Awad
For more, check out the License File.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_seeding-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47cd396a251e0b11807f9ebb539d13f06f7758d1cc99b0ffe8e242f1a094709c |
|
MD5 | c682cb623821cbd0f1e4a8eb8d782358 |
|
BLAKE2b-256 | 098eb3284305ead3e702fecd145d146e968db4ec4aae461f8d8565ae4c58706a |