Skip to content

Commit

Permalink
fix for notification create
Browse files Browse the repository at this point in the history
  • Loading branch information
KlemenSpruk committed Oct 18, 2023
1 parent 4f93646 commit 20a549a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions django_project_base/notifications/rest/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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(
Expand All @@ -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)
Expand Down

0 comments on commit 20a549a

Please sign in to comment.