A library to facilitate the creation of fake data (seeds) in Django projects.
Reason this release was yanked:
broken
Project description
jessilver_django_seed
jessilver_django_seed is a library for the Django framework that facilitates the creation of data (seeds) to populate the database during development and testing. With jessilver_django_seed, you can quickly generate realistic data for your Django applications, which is useful for testing functionalities and visualizing how the application behaves with different types of data.
Features
- Fake data generation: Easily create test data for your Django models.
- Simple configuration: Easy integration with existing Django projects.
Configuration
Installation
Install the library:
pip install jessilver_django_seed
Adding to the Project
Add jessilver_django_seed to INSTALLED_APPS in your settings.py file:
INSTALLED_APPS = [
...
'jessilver_django_seed',
]
Create a constant called SEEDER_APPS to define the apps you want to populate with fake data:
SEEDER_APPS = [
'app1',
'app2',
...
]
Usage
Directory Structure
Inside the folder of the apps added in SEEDER_APPS, create a directory called seeders:
app1/
├── ...
├── seeders/
└── ...
Creating Seeders
Inside the seeders directory, you can create files to define the data you want to generate. For example, a file called user_seeder.py:
To create a seeder, you need to implement two main functions: seeder_name and seed. I will explain each of them:
-
seeder_nameThis function is responsible for returning the name of the seeder. This name is generally used to uniquely identify the seeder within the system. It can be useful for organizational purposes and to ensure that the correct seeder is being executed.
Example:
def seeder_name(): return "UserSeeder"
-
seedThis function is where the data insertion logic is implemented. It is responsible for populating the database with the desired data. The
seedfunction usually contains commands to create records in the database, using models or direct queries.Example:
def seed(): users = [ {"name": "Alice", "email": "alice@example.com"}, {"name": "Bob", "email": "bob@example.com"}, ] for user in users: # Assuming you have a User model User.create(**user)
Example of a complete seeder:
from jessilver_django_seed.seeders.BaseSeeder import BaseSeeder
from django.contrib.auth.models import User
class SuperUserSeeder(BaseSeeder):
@property
def seeder_name(self):
return 'SuperUserSeeder'
def seed(self):
if not User.objects.filter(is_superuser=True).exists():
User.objects.create_superuser(
username='admin',
email='admin@example.com',
password='123456789',
first_name='Admin',
last_name='User'
)
self.success(f'Super User created')
else:
self.error(f'Super User already exists')
You can create multiple files or just one containing multiple classes. The only requirement is that the class names end with Seeder, otherwise, it will not work.
For example, you can create a file seeders.py with multiple classes:
from jessilver_django_seed.seeders.BaseSeeder import BaseSeeder
from django.contrib.auth.models import User
from myapp.models import Profile
class SuperUserSeeder(BaseSeeder):
@property
def seeder_name(self):
return 'SuperUserSeeder'
def seed(self):
if not User.objects.filter(is_superuser=True).exists():
User.objects.create_superuser(
username='admin',
email='admin@example.com',
password='123456789',
first_name='Admin',
last_name='User'
)
self.success(f'Super User created')
else:
self.error(f'Super User already exists')
class ProfileSeeder(BaseSeeder):
@property
def seeder_name(self):
return 'ProfileSeeder'
def seed(self):
for user in User.objects.all():
Profile.objects.get_or_create(user=user, defaults={
'bio': 'This is a bio',
'location': 'Unknown'
})
self.success(f'Profile created for user {user.username}')
Running the Seeders
Now, you can run the command to populate the database with fake data:
python manage.py seed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jessilver_django_seed-0.1.3.tar.gz.
File metadata
- Download URL: jessilver_django_seed-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69151e0c22520a0bad6c37c9e13ba987df7dde4461f8473507131dbc8ec33316
|
|
| MD5 |
9fb9b78a47c71d7cf2bb5c4f6536e051
|
|
| BLAKE2b-256 |
a9c8340964b53ada6f250621d5baaba35b2e5ea2c49e9723f1283a6b6cc698d3
|
File details
Details for the file jessilver_django_seed-0.1.3-py3-none-any.whl.
File metadata
- Download URL: jessilver_django_seed-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f083e474a1ea46b9b8e3fb2dcb140919aad88cd6dcaac78cb7a80306f23897d
|
|
| MD5 |
88290e0b234e89514ab5e08739fe9197
|
|
| BLAKE2b-256 |
440e5c96f3706a05affa8b538e58a846d8daf19f7915fbea6d1d2849f7cb06e4
|