https://github.com/model-bakers/model_bakery
Object factory for Django
https://github.com/model-bakers/model_bakery
django fixtures object-factory python
Last synced: 5 days ago
JSON representation
Object factory for Django
- Host: GitHub
- URL: https://github.com/model-bakers/model_bakery
- Owner: model-bakers
- License: other
- Created: 2019-10-08T12:49:08.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-07T11:18:20.000Z (about 1 month ago)
- Last Synced: 2025-04-09T19:14:16.543Z (5 days ago)
- Topics: django, fixtures, object-factory, python
- Language: Python
- Homepage: https://model-bakery.readthedocs.io/en/latest/
- Size: 586 KB
- Stars: 884
- Watchers: 10
- Forks: 93
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- -awesome-django - model-bakery - Object factory for Django (rename of legacy Model Mommy project). (Third-Party Packages / Testing)
- awesome-django - model-bakery - Object factory for Django (rename of legacy Model Mommy project). (Third-Party Packages / Testing)
- awesome-python-testing - Model Bakery - offers you a smart way to create fixtures for testing in Django. (Object Factories)
- best-of-web-python - GitHub - 22% open · ⏱️ 03.06.2024): (Web Testing)
README
# Model Bakery: Smart fixtures for better tests
[](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
[](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
[](https://pypi.python.org/pypi/model_bakery/)
[](https://model-bakery.readthedocs.io/en/latest/?badge=latest)*Model 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.
> **Note:** Model Bakery is a rename of the legacy [Model Mommy project](https://pypi.org/project/model_mommy/).
## Installation
```bash
pip install model-bakery
```## Basic usage
```python
# models.py
from django.db import modelsclass 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 bakerclass TestCustomerModel(TestCase):
def setUp(self):
self.customer = baker.make('shop.Customer')
print(self.customer.__dict__)"""
{'_state': ,
'age': 3841,
'bio': 'vUFzMUMyKzlnTyiCxfgODIhrnkjzgQwHtzIbtnVDKflqevczfnaOACkDNqvCHwvtWdLwoiKrCqfppAlogSLECtMmfleeveyqefkGyTGnpbkVQTtviQVDESpXascHAluGHYEotSypSiHvHzFteKIcUebrzUVigiOacfnGdvijEPrZdSCIIBjuXZMaWLrMXyrsUCdKPLRBRYklRdtZhgtxuASXdhNGhDsrnPHrYRClhrSJSVFojMkUHBvSZhoXoCrTfHsAjenCEHvcLeCecsXwXgWJcnJPSFdOmOpiHRnhSgRF',
'birthday': datetime.date(2019, 12, 3),
'email': '[email protected]',
'is_jards_macale_fan': True,
'id': 1,
'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx'}
"""
```## Documentation
For more detailed information, check out the [full documentation](https://model-bakery.readthedocs.io/).
## Contributing
As an open-source project, Model Bakery welcomes contributions of many forms:
- Code patches
- Documentation improvements
- Bug reportsTake a look at our [contribution guidelines](CONTRIBUTING.md) for instructions
on how to set up your local environment.## Maintainers
- [Bernardo Fontes](https://github.com/berinhard/)
- [Rustem Saiargaliev](https://github.com/amureki/)
- [Tim Klein](https://github.com/timjklein36)## Creator
- [Vanderson Mota](https://github.com/vandersonmota/)
## License
Model Bakery is licensed under the MIT License.
See the [LICENSE](LICENSE) file for more information.