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: