From 24b4b1fad07685cadf2100d6802b2b9ddf9a33da Mon Sep 17 00:00:00 2001 From: moanos Date: Fri, 2 Aug 2024 19:31:32 +0200 Subject: [PATCH] feat: add basic subscriptions --- src/fellchensammlung/models.py | 6 ++++++ src/fellchensammlung/views.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index a5dd806..1c90f4b 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -552,3 +552,9 @@ class BaseNotification(models.Model): class CommentNotification(BaseNotification): comment = models.ForeignKey(Comment, on_delete=models.CASCADE, verbose_name=_('Antwort')) + + +class Subscriptions(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in')) + adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE, verbose_name=_('AdoptionNotice')) + created_at = models.DateTimeField(auto_now_add=True) \ No newline at end of file diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 0b809f7..e4cd7de 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -12,7 +12,7 @@ from notfellchen import settings from fellchensammlung import logger from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \ - User, Location, AdoptionNoticeStatus + User, Location, AdoptionNoticeStatus, Subscriptions from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \ CommentForm, ReportCommentForm, AnimalForm, \ AdoptionNoticeSearchForm, AnimalFormWithDateWidget @@ -61,6 +61,10 @@ def adoption_notice_detail(request, adoption_notice_id): comment_instance.adoption_notice_id = adoption_notice_id comment_instance.user = request.user.member comment_instance.save() + + # Auto-subscribe user to adoption notice + subscription = Subscriptions(adoption_notice=adoption_notice, user=request.user) + subscription.save() else: raise PermissionDenied else: