A model instances generator for Django
Project description
An easy-to-use implementation of Creation Methods for Django, backed by Faker.
django_fakery will try to guess the field’s value based on the field’s name and type.
QuickStart
from django_fakery.factory import factory factory.make('auth.User', quantity=4)
Blueprints
from django_fakery.blueprint import Blueprint user = Blueprint('auth.User') user.make(quantity=10)
If you want to ensure uniqueness when generating multiple objects, you can use a lambda function.
In this example, n is the iteration number, and f is an instance of faker:
user = Blueprint( 'auth.User', fields={ 'username': lambda n, f: 'user_%s' % n, } )
For convenience, when the value is a string, you can simply pass a formatting string:
user = Blueprint( 'auth.User', fields={ 'username': 'user_%(n)s', } )
Blueprints can refer other blueprints:
pizza = Blueprint( 'food.Pizza', fields={ 'chef': user, } )
Seeding the faker
from django_fakery.factory import Factory factory = Factory() factory.seed(1234) factory.make('auth.User', fields={ 'username': 'regularuser' }, seed=1234, quantity=4)
from django_fakery.factory import factory factory.make('auth.User', fields={ 'username': 'regularuser' }, seed=1234, quantity=4)
License
This software is released under the MIT License.
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
django-fakery-0.0.1.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for django_fakery-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5768819ae4d8ff4dba94a106615cb2b5e9e94bacbb44742239d6e6b4f898614 |
|
MD5 | 33f36cb4a793489a982939c2878fd750 |
|
BLAKE2b-256 | d4a2e78d05cef1684ea0e87826acbae77b0839071c6d44c44b5be1aa1b580a5b |