From 20a549a3a1a411a1b78a25c8fa7165c494f3ef41 Mon Sep 17 00:00:00 2001 From: KlemenSpruk Date: Wed, 18 Oct 2023 08:40:07 +0200 Subject: [PATCH] fix for notification create --- .../notifications/rest/notification.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/django_project_base/notifications/rest/notification.py b/django_project_base/notifications/rest/notification.py index f405cd80..84a40be5 100644 --- a/django_project_base/notifications/rest/notification.py +++ b/django_project_base/notifications/rest/notification.py @@ -409,7 +409,7 @@ def filter_queryset_field(self, queryset, field, value): return super().filter_queryset_field(queryset, field, value) def get_serializer_class(self): - if not self.detail and self.action == "create": + if self.action in ("create", "update"): class NewMessageSerializer(Serializer): message_body = NotificationSerializer().fields.fields["message_body"] @@ -434,7 +434,7 @@ def get_queryset(self): except ProjectNotSelectedError as e: raise NotFound(e.message) - def perform_create(self, serializer): + def _create_notification(self, serializer): host_url = get_host_url(self.request) notification = Notification( message=DjangoProjectBaseMessage( @@ -460,6 +460,17 @@ def perform_create(self, serializer): ) notification.send() + def update(self, request, *args, **kwargs): + kwargs.pop("pk", None) + return super().create(request, *args, **kwargs) + + def create(self, request, *args, **kwargs): + kwargs.pop("pk", None) + return super().create(request, *args, **kwargs) + + def perform_create(self, serializer): + return self._create_notification(serializer) + class ChannelSerializer(Serializer): available = fields.FloatField(read_only=True, display_table=DisplayMode.HIDDEN)