From 0b08647c7e1b97bd8ab20fdf3fd56780fc75a6e1 Mon Sep 17 00:00:00 2001 From: moanos Date: Sat, 3 Aug 2024 09:02:09 +0200 Subject: [PATCH] feat: Link to comment --- src/fellchensammlung/models.py | 5 +++++ .../fellchensammlung/partials/partial-notification.html | 2 +- src/fellchensammlung/views.py | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 36991b3..5bfc894 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -559,6 +559,11 @@ class BaseNotification(models.Model): class CommentNotification(BaseNotification): comment = models.ForeignKey(Comment, on_delete=models.CASCADE, verbose_name=_('Antwort')) + @property + def url(self): + print(f"URL: self.comment.get_absolute_url()") + return self.comment.get_absolute_url + class Subscriptions(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in')) diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html b/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html index 816799e..6ba642b 100644 --- a/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html +++ b/src/fellchensammlung/templates/fellchensammlung/partials/partial-notification.html @@ -2,7 +2,7 @@ {% load custom_tags %}
- {{ notification.title }} + {{ notification.title }} {{ notification.created_at }}
{% csrf_token %} diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 719a10b..2c70ff7 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -322,11 +322,11 @@ def user_detail(request, user_id): if action == "notification_mark_read": notification_id = request.POST.get("notification_id") print(notification_id) - notification = BaseNotification.objects.get(pk=notification_id) + notification = CommentNotification.objects.get(pk=notification_id) notification.read = True notification.save() elif action == "notification_mark_all_read": - notifications = BaseNotification.objects.filter(user=request.user, mark_read=False) + notifications = CommentNotification.objects.filter(user=request.user, mark_read=False) for notification in notifications: notification.read = True notification.save() @@ -334,7 +334,7 @@ def user_detail(request, user_id): user = User.objects.get(id=user_id) context = {"user": user, "adoption_notices": AdoptionNotice.objects.filter(created_by=user), - "notifications": BaseNotification.objects.filter(user=user, read=False)} + "notifications": CommentNotification.objects.filter(user=user, read=False)} return render(request, 'fellchensammlung/details/detail-user.html', context=context)