Skip to main content

No project description provided

Project description

repo-size forks stars issues contributors pr hachtoberfest license

Django Seeding

Report Bug · Request Feature

photo


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-seeding-1.0.5.tar.gz (14.0 kB view hashes)

Uploaded Source

Built Distribution

django_seeding-1.0.5-py3-none-any.whl (13.2 kB view hashes)

Uploaded Python 3

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