From 454986c0a62b8174f1933c852015474d041e02fb Mon Sep 17 00:00:00 2001 From: Katherine-Greg Date: Mon, 18 Dec 2023 18:24:29 +0200 Subject: [PATCH] Fixed create borrowings feature --- borrowing_service/signals.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/borrowing_service/signals.py b/borrowing_service/signals.py index 7dc418e..9197fc9 100644 --- a/borrowing_service/signals.py +++ b/borrowing_service/signals.py @@ -10,13 +10,16 @@ @receiver(post_save, sender=Borrowing) def notify_new_borrowing(sender, instance, created, **kwargs): if created: - borrowing_info = ( - "New borrowing created:\n\n" - f"-Book: {instance.book}\n" - f"--Borrow date: {instance.borrow_date}\n" - f"--Expected return date: {instance.expected_return_date}\n" - ) - send_notification( - TelegramUser.objects.get(user_id=instance.user_id).chat_id, - borrowing_info - ) + try: + borrowing_info = ( + "New borrowing created:\n\n" + f"-Book: {instance.book}\n" + f"--Borrow date: {instance.borrow_date}\n" + f"--Expected return date: {instance.expected_return_date}\n" + ) + send_notification( + TelegramUser.objects.get(user_id=instance.user_id).chat_id, + borrowing_info + ) + except TelegramUser.DoesNotExist: + pass