-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signals folder created to hold every signals on delete book, a signal delete the book file, cover image physically from the file directory
- Loading branch information
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# book_api/signals/__init__.py | ||
from book_api.signals.book_delete import delete_book_files | ||
|
||
|
||
__all__ = [ | ||
delete_book_files, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.db.models.signals import post_delete | ||
from django.dispatch import receiver | ||
|
||
from book_api.models import Book | ||
|
||
|
||
@receiver(post_delete, sender=Book) | ||
def delete_book_files(sender, instance, *args, **kwargs): | ||
print(instance) | ||
if instance.book: | ||
instance.book.delete(save=False) | ||
|
||
if instance.cover_image: | ||
instance.cover_image.delete(save=False) |