Commit 0e49b20 1 parent aa2ab44 commit 0e49b20 Copy full SHA for 0e49b20
File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8
8
## [ Unreleased] ( https://github.com/model-bakers/model_bakery/tree/main )
9
9
10
10
### Added
11
+ - docs: Add missing doc on ` _refresh_after_create ` option
11
12
12
13
### Changed
13
14
- Fix ` Recipe.prepare ` without _ quantity (on one-to-one relation)
Original file line number Diff line number Diff line change @@ -242,6 +242,24 @@ Model Bakery does not create files for FileField types. If you need to have the
242
242
243
243
** Important** : the lib does not do any kind of file clean up, so it's up to you to delete the files created by it.
244
244
245
+ ## Refreshing Instances After Creation
246
+
247
+ By default, Model Bakery does not refresh the instance after it is created and saved.
248
+ If you want to refresh the instance after it is created,
249
+ you can pass the flag ` _refresh_after_create=True ` to either ` baker.make ` or ` baker.make_recipe ` .
250
+ This ensures that any changes made by the database or signal handlers are reflected in the instance.
251
+
252
+ ``` python
253
+ from model_bakery import baker
254
+
255
+ # default behavior
256
+ customer = baker.make(' shop.Customer' , birthday = ' 1990-01-01' , _refresh_after_create = False )
257
+ assert customer.birthday == ' 1990-01-01'
258
+
259
+ customer = baker.make(' shop.Customer' , birthday = ' 1990-01-01' , _refresh_after_create = True )
260
+ assert customer.birthday == datetime.date(1990 , 1 , 1 )
261
+ ```
262
+
245
263
## Non persistent objects
246
264
247
265
If you don't need a persisted object, Model Bakery can handle this for you as well with the ** prepare** method:
You can’t perform that action at this time.
0 commit comments