diff --git a/project/notification/models.py b/project/notification/models.py index c9ff4f97..641758c7 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})"