diff --git a/docs/README.md b/docs/README.md index 4a63c9ed..88c2c0a9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -38,6 +38,8 @@ This solves the problem introduced by using `instance.pk = None` and `instance.s * [List View](#list-view) * [Change View](#change-view) * [CloneModelAdmin class attributes](#clonemodeladmin-class-attributes) + * [Signals](#signals) + * [pre\_clone\_save, post\_clone\_save](#pre_clone_save-post_clone_save) * [Compatibility](#compatibility) * [Running locally](#running-locally) * [Found a Bug?](#found-a-bug) @@ -340,6 +342,31 @@ INSTALLED_APPS = [ ] ``` +### Signals + +#### pre\_clone\_save, post\_clone\_save + +```python +from django.dispatch import receiver +from django.utils import timezone + +from model_clone.signals import post_clone_save, pre_clone_save + +from sample.models import Edition + + +@receiver(pre_clone_save, sender=Edition) +def increase_seq(sender, instance, **kwargs): + instance.seq += 1 + + +@receiver(post_clone_save, sender=Edition) +def update_book_published_at(sender, instance, **kwargs): + if instance.book: + instance.book.published_at = timezone.now() + instance.book.save(update_fields=["published_at"]) +``` + ## Compatibility | Python | Supported version | @@ -393,16 +420,16 @@ Thanks goes to these wonderful people: