Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Django specific Extensions for Factory Boy

Project description


FactoryMan provides Django specific extensions for Factory Boy.


pip install factory-man


FactoryMan provides you with a factory function create_populated_modelfactory, which accepts the model class and automatically creates a factory class based on the model's fields. If you want to override some fields, you can pass them as keyword arguments to the __init__ method.

from factoryman import create_populated_modelfactory
from .models import Project

ProjectFactory = create_populated_modelfactory(Project)

ExpiredProjectFactory = create_populated_modelfactory(Project, deadline='1999-04-04')

To override the factory's _create method, use create_override keyword argument. This is useful to create many-to-many connections as described in the Factory Boy documentation.

Check out this article for a more detailed user guide.

Low-level Features

ModelFieldSequence extends factory.Sequence to provide a little more DRY syntax. It accepts a Django model class as parameter and uses the class name togeteher with the field name to which it is bound to for creating an unique value.

Alternatively, it can accept a string parameter, which will be used directly instead of a name derived from the class and field.


from factory.django import DjangoModelFactory as ModelFactory
from factoryman import ModelFieldSequence

class CharityFactory(ModelFactory):
    class Meta:
        model = Charity

    name = ModelFieldSequence(Charity)  # Will be `Charity__name-n`, where n is the object count
    email = ModelFieldSequence(string='')  # Will be ``, where n is the object count

Project details

Download files

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

Files for factory-man, version 1.2.3
Filename, size File type Python version Upload date Hashes
Filename, size factory_man-1.2.3-py3-none-any.whl (5.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size factory-man-1.2.3.tar.gz (4.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page