Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin committed Aug 1, 2024
1 parent a657d87 commit c162711
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/source/signal-decorator.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ Notes:
2. The function decorated by `after_create_commit`, `after_update_commit`, receive the same arguments as `post_save` signal handler.
3. The function decorated by `after_delete_commit` receive the same arguments as `post_delete` signal handler.
4. This can make our code more clear, especially when we need to some broadcasts.

## django-lifecycle

Another approach is to use `django-lifecycle` package, which is inspired by Rails' `ActiveRecord` callbacks.

So we can write the code in Django model like this:

```python
@hook(AFTER_UPDATE, on_commit=True)
def broadcast_updated(self):
pass

@hook(BEFORE_DELETE)
def broadcast_deleted(self):
pass
```

0 comments on commit c162711

Please sign in to comment.