🎭 Intelligent test data generation for Django applications with advanced field introspection
Project description
django-fakegen
A Django package for generating smart fake data for your models. It leverages Faker to automatically populate Django models with realistic data, supporting a wide range of field types, including relations.
Features
- Generate fake data for any Django model, including related fields
- Supports bulk generation
- Customizable via field overrides
- CLI integration via Django management command
Installation
pip install django-fakegen
Add django_fakegen to your INSTALLED_APPS if needed (not strictly required for management command usage).
Example:
# settings.py
INSTALLED_APPS = [
# ...
'django_fakegen',
# ...
]
Usage
Command Line
Generate 10 fake instances for a model:
python manage.py fakegen app_label.ModelName
Generate a custom number of instances:
python manage.py fakegen app_label.ModelName --count 50
Programmatic Usage
You can use the registry directly in your code:
from django_fakegen.registry import registry
# Generate a single instance
instance = registry.generate_instance(MyModel)
# Generate multiple instances
instances = registry.bulk_generate('app_label.ModelName', count=20)
Supported Fields
django-fakegen supports the following Django field types:
| Field Type | Generator Behavior |
|---|---|
| CharField | Title-like string, respects max_length |
| TextField | Realistic text, up to 250 chars |
| IntegerField | Random integer (0-100) |
| PositiveIntegerField | Random integer (0-100) |
| FloatField | Random float (5 digits left, 2 right) |
| BooleanField | Random boolean |
| DateTimeField | Random datetime (this year) |
| DateField | Random date (this year) |
| TimeField | Random time |
| EmailField | Random email address |
| ForeignKey | Random related instance |
| OneToOneField | Random related instance |
| ManyToManyField | List of 3 random related instances |
Example
Suppose you have a model:
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField()
class Book(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
published = models.BooleanField()
author = models.ForeignKey(Author, on_delete=models.CASCADE)
You can generate fake data for Book (and related Author) with:
python manage.py fakegen myapp.Book --count 5
Or programmatically:
from django_fakegen.registry import registry
books = registry.bulk_generate('myapp.Book', count=5)
Extending
You can add your own field generators by subclassing BaseFieldGenerator and adding them to the registry.
Contributing
Contributions are welcome! If you'd like to help improve django-fakegen, please open an issue or submit a pull request on GitHub.
License
MIT
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 django_fakegen-3.3.4.tar.gz.
File metadata
- Download URL: django_fakegen-3.3.4.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f780d27fe700ecbd3217dad124fcb8fae99bee709965b18f3e8924ed05d9398
|
|
| MD5 |
394984380576a12d5ecbabf103e8505d
|
|
| BLAKE2b-256 |
55510e17c74dca30cb7465b634b243112d8538848a4e7e551024ef6cf1047384
|
File details
Details for the file django_fakegen-3.3.4-py3-none-any.whl.
File metadata
- Download URL: django_fakegen-3.3.4-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59dc9882be526ce1b75b2a3ff0d1a366e3e8e5b7620b7f3c3ea9c0fdb3b55c18
|
|
| MD5 |
d4a5abad1f2d79fd5f29df1dc178ed98
|
|
| BLAKE2b-256 |
736ef031c72b9a91491b1eaf72d2595bec3dfbaa3bbc70e563a12ffb447c7d5f
|