feat: add basic subscriptions

This commit is contained in:
moanos [he/him] 2024-08-02 19:31:32 +02:00
parent 7c8dcaf171
commit 24b4b1fad0
2 changed files with 11 additions and 1 deletions

View File

@ -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)

View File

@ -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: