Object factory for Django
See the codeModel Bakery offers you a smart way to create fixtures for testing in Django. With a simple and powerful API, you can create many objects with a single line of code.
pip install model-bakery
Model Bakery follows the Python and Django release and support cycles. We drop support for Python and Django versions when they reach end-of-life.
# models.py
from django.db import models
class Customer(models.Model):
name = models.CharField(max_length=30)
email = models.EmailField()
age = models.IntegerField()
is_jards_macale_fan = models.BooleanField()
bio = models.TextField()
birthday = models.DateField()
last_shopping = models.DateTimeField()
# test_models.py
from django.test import TestCase
from model_bakery import baker
class TestCustomerModel(TestCase):
def setUp(self):
self.customer = baker.make('shop.Customer')
print(self.customer.__dict__)
"""
{'_state': <django.db.models.base.ModelState object at 0x1129a3240>,
'age': 3841,
'bio': 'vUFzMUMyKzlnTyiCxfgODIhrnkjzgQwHtzIbtnVDKflqevczfnaOACkDNqvCHwvtWdLwoiKrCqfppAlogSLECtMmfleeveyqefkGyTGnpbkVQTtviQVDESpXascHAluGHYEotSypSiHvHzFteKIcUebrzUVigiOacfnGdvijEPrZdSCIIBjuXZMaWLrMXyrsUCdKPLRBRYklRdtZhgtxuASXdhNGhDsrnPHrYRClhrSJSVFojMkUHBvSZhoXoCrTfHsAjenCEHvcLeCecsXwXgWJcnJPSFdOmOpiHRnhSgRF',
'birthday': datetime.date(2019, 12, 3),
'email': 'rpNATNsxoj@example.com',
'is_jards_macale_fan': True,
'id': 1,
'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx'}
"""
For more detailed information, check out the full documentation.
As an open-source project, Model Bakery welcomes contributions of many forms:
Take a look at our contribution guidelines for instructions on how to set up your local environment.
Model Bakery is built by its community. See the full list of contributors.
Model Bakery was originally created by Vanderson Mota as Model Mommy. The project was previously maintained in the berinhard/model_mommy repository before being renamed and moved here.
Model Bakery is licensed under Apache License 2.0. See the LICENSE file for more information.
Overall
Maintained
Code review
PyPI
Latest release
Releases this year
376 followers · starred Jan 2023
160 followers · starred Jan 2024
517 followers · starred Dec 2019
76 followers · starred Sep 2022
Object factory for Django
See the codeModel Bakery offers you a smart way to create fixtures for testing in Django. With a simple and powerful API, you can create many objects with a single line of code.
pip install model-bakery
Model Bakery follows the Python and Django release and support cycles. We drop support for Python and Django versions when they reach end-of-life.
# models.py
from django.db import models
class Customer(models.Model):
name = models.CharField(max_length=30)
email = models.EmailField()
age = models.IntegerField()
is_jards_macale_fan = models.BooleanField()
bio = models.TextField()
birthday = models.DateField()
last_shopping = models.DateTimeField()
# test_models.py
from django.test import TestCase
from model_bakery import baker
class TestCustomerModel(TestCase):
def setUp(self):
self.customer = baker.make('shop.Customer')
print(self.customer.__dict__)
"""
{'_state': <django.db.models.base.ModelState object at 0x1129a3240>,
'age': 3841,
'bio': 'vUFzMUMyKzlnTyiCxfgODIhrnkjzgQwHtzIbtnVDKflqevczfnaOACkDNqvCHwvtWdLwoiKrCqfppAlogSLECtMmfleeveyqefkGyTGnpbkVQTtviQVDESpXascHAluGHYEotSypSiHvHzFteKIcUebrzUVigiOacfnGdvijEPrZdSCIIBjuXZMaWLrMXyrsUCdKPLRBRYklRdtZhgtxuASXdhNGhDsrnPHrYRClhrSJSVFojMkUHBvSZhoXoCrTfHsAjenCEHvcLeCecsXwXgWJcnJPSFdOmOpiHRnhSgRF',
'birthday': datetime.date(2019, 12, 3),
'email': 'rpNATNsxoj@example.com',
'is_jards_macale_fan': True,
'id': 1,
'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx'}
"""
For more detailed information, check out the full documentation.
As an open-source project, Model Bakery welcomes contributions of many forms:
Take a look at our contribution guidelines for instructions on how to set up your local environment.
Model Bakery is built by its community. See the full list of contributors.
Model Bakery was originally created by Vanderson Mota as Model Mommy. The project was previously maintained in the berinhard/model_mommy repository before being renamed and moved here.
Model Bakery is licensed under Apache License 2.0. See the LICENSE file for more information.
Overall
Maintained
Code review
PyPI
Latest release
Releases this year
376 followers · starred Jan 2023
160 followers · starred Jan 2024
517 followers · starred Dec 2019
76 followers · starred Sep 2022