Skip to content

Commit

Permalink
docs: Add Django settings example for custom field generators (#491)
Browse files Browse the repository at this point in the history
In Custom Fields doc added example for adding custom field mapping through Django settings.

Co-authored-by: pclararoblesiati <pau.c@iatiseguros.com>
  • Loading branch information
pclararobles and pclararoblesiati authored Aug 16, 2024
1 parent 9f9c0e3 commit e2913a8
Showing 1 changed file with 8 additions and 0 deletions.
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

0 comments on commit e2913a8

Please sign in to comment.