Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add Django settings example for custom field generators #491

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/how_bakery_behaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Require `django.contrib.gis` in `INSTALLED_APPS`:

Model Bakery allows you to define generators methods for your custom fields or overrides its default generators.
This can be achieved by specifying the field and generator function for the `generators.add` function.
It can also be done by specifying the field and generator function in the `BAKER_CUSTOM_FIELDS_GEN` setting.
Both can be the real python objects imported in settings or just specified as import path string.

Examples:
Expand All @@ -78,6 +79,13 @@ from model_bakery import baker
baker.generators.add('test.generic.fields.CustomField', 'code.path.gen_func')
```

```python
# in your settings.py file:
BAKER_CUSTOM_FIELDS_GEN = {
'test.generic.fields.CustomField': 'code.path.gen_func',
}
```

## Customizing Baker

In some rare cases, you might need to customize the way Baker base class behaves.
Expand Down