From 639de578f619dacf75e75f4884d0c384d5acaac7 Mon Sep 17 00:00:00 2001 From: Seungwoo Son Date: Tue, 10 Dec 2024 15:26:36 -0800 Subject: [PATCH] Modify models.py --- project/notification/models.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/project/notification/models.py b/project/notification/models.py index c9ff4f972..641758c72 100644 --- a/project/notification/models.py +++ b/project/notification/models.py @@ -3,32 +3,38 @@ Notifies users about new followers or replies. """ from django.db import models - from accounts.models import Profile from threads.models import Civi, Thread +from enum import Enum + +class ActivityType(Enum): + NEW_FOLLOWER = "new_follower" + RESPONSE_TO_CIVI = "response_to_your_civi" + REBUTTAL_TO_RESPONSE = "rebuttal_to_your_response" class Notification(models.Model): account = models.ForeignKey( - Profile, default=None, null=True, on_delete=models.PROTECT + Profile, null=True, on_delete=models.PROTECT, + help_text="The profile receiving the notification." ) thread = models.ForeignKey( - Thread, default=None, null=True, on_delete=models.PROTECT + Thread, null=True, on_delete=models.PROTECT, + help_text="The thread related to the notification." ) civi = models.ForeignKey( - Civi, default=None, null=True, on_delete=models.PROTECT - ) # always a solution or null - - # Need to go to bed but there are going to be SO MANY OF THESE - activity_CHOICES = ( - ("new_follower", "New follower"), - ("response_to_yout_civi", "Response to your civi"), - ("rebuttal_to_your_response", "Rebuttal to your response"), + Civi, null=True, on_delete=models.PROTECT, + help_text="The Civi solution associated with the notification, if any." ) + + activity_CHOICES = [(tag.value, tag.name.replace("_", " ").capitalize()) for tag in ActivityType] activity_type = models.CharField( - max_length=31, default="new_follower", choices=activity_CHOICES + max_length=31, default=ActivityType.NEW_FOLLOWER.value, choices=activity_CHOICES ) read = models.BooleanField(default=False) - created = models.DateTimeField(auto_now_add=True, blank=True, null=True) - last_modified = models.DateTimeField(auto_now=True, blank=True, null=True) + created = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + + def __str__(self): + return f"Notification({self.account}, {self.activity_type})"