Skip to content

Commit

Permalink
Merge pull request #20 from rkshaon/rkshaon
Browse files Browse the repository at this point in the history
feat: backend - book delete
  • Loading branch information
rkshaon authored Sep 8, 2024
2 parents 5f6b30a + 7a773d0 commit 6f3bacc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/book_api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
class BookApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'book_api'

def ready(self) -> None:
import book_api.signals # noqa
return super().ready()
7 changes: 7 additions & 0 deletions backend/book_api/signals/__init__.py
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,
]
14 changes: 14 additions & 0 deletions backend/book_api/signals/book_delete.py
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)

0 comments on commit 6f3bacc

Please sign in to comment.