Skip to main content

A Django app for generating fake data using Faker.

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).

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.

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

django_fakegen-3.2.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_fakegen-3.2.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file django_fakegen-3.2.3.tar.gz.

File metadata

  • Download URL: django_fakegen-3.2.3.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_fakegen-3.2.3.tar.gz
Algorithm Hash digest
SHA256 bb2825bef59fe18e9443afb339bb0ee76c66284bc35f911ae1ce81ac7bcaaa0d
MD5 4caca1867935b7813f8d4754aacd7e36
BLAKE2b-256 734926f15e85deb85f405fbc2dc9b5b01946667dbe0ac9c2fb221b35a9e4d2f3

See more details on using hashes here.

File details

Details for the file django_fakegen-3.2.3-py3-none-any.whl.

File metadata

  • Download URL: django_fakegen-3.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_fakegen-3.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 52b876ce9639e7fb5cc762c8fb8657d336f1c2b480026433d5bc25a386b07348
MD5 c281ddc3595b5f1c1785546bdce435d6
BLAKE2b-256 ad0cfd291add026f34daacca3b03798e0b5c812e81a1135e0957a17d77aca548

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