Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
amcclosky committed Jan 31, 2022
1 parent 9435f1f commit a69e64b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ Or you want to email a user when their account is deleted. You could add the dec
)
```

Or if you want to enqueue a background job that depends on state being committed to your database

```python
@hook(AFTER_CREATE, on_commit=True)
def do_after_create_jobs(self):
enqueue_job(send_item_shipped_notication, self.item_id)
```

Read on to see how to only fire the hooked method if certain conditions about the model's current and previous state are met.

## Transitions between specific values
Expand Down
2 changes: 2 additions & 0 deletions docs/hooks_and_conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can hook into one or more lifecycle moments by adding the `@hook` decorator
was: Any = '*',
was_not: Any = None,
changes_to: Any = None,
on_commit: Optional[bool] = None
):
```
## Lifecycle Moments
Expand Down Expand Up @@ -52,3 +53,4 @@ If you do not use any conditional parameters, the hook will fire every time the
| was | Any | Only fire the hooked method if the value of the `when` field was equal to this value when first initialized; defaults to `*`. |
| was_not | Any | Only fire the hooked method if the value of the `when` field was NOT equal to this value when first initialized. |
| 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. |
| 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 comments on commit a69e64b

Please sign in to comment.