Skip to content

Commit a69e64b

Browse files
committed
update documentation
1 parent 9435f1f commit a69e64b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/examples.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ Or you want to email a user when their account is deleted. You could add the dec
2828
)
2929
```
3030

31+
Or if you want to enqueue a background job that depends on state being committed to your database
32+
33+
```python
34+
@hook(AFTER_CREATE, on_commit=True)
35+
def do_after_create_jobs(self):
36+
enqueue_job(send_item_shipped_notication, self.item_id)
37+
```
38+
3139
Read on to see how to only fire the hooked method if certain conditions about the model's current and previous state are met.
3240

3341
## Transitions between specific values

docs/hooks_and_conditions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ You can hook into one or more lifecycle moments by adding the `@hook` decorator
1717
was: Any = '*',
1818
was_not: Any = None,
1919
changes_to: Any = None,
20+
on_commit: Optional[bool] = None
2021
):
2122
```
2223
## Lifecycle Moments
@@ -52,3 +53,4 @@ If you do not use any conditional parameters, the hook will fire every time the
5253
| was | Any | Only fire the hooked method if the value of the `when` field was equal to this value when first initialized; defaults to `*`. |
5354
| was_not | Any | Only fire the hooked method if the value of the `when` field was NOT equal to this value when first initialized. |
5455
| changes_to | Any | Only fire the hooked method if the value of the `when` field was NOT equal to this value when first initialized but is currently equal to this value. |
56+
| on_commit | bool | When `True` only fire the hooked method after the current database transaction has been commited or not at all. (Only applies to `AFTER_*` hooks) |

0 commit comments

Comments
 (0)