Coverage for modules\notifications\models.py: 94%

16 statements  

« prev     ^ index     » next       coverage.py v7.16.0, created at 2026-09-05 09:19 +0800

1from django.db import models 

2from core.models import TenantScopedModel 

3from modules.authentication.models import User 

4 

5class Notification(TenantScopedModel): 

6 """User Notification entity.""" 

7 TYPE_CHOICES = [ 

8 ('DEAL_WON', 'Deal Won'), 

9 ('INVOICE_PAID', 'Invoice Paid'), 

10 ('TASK_ASSIGNED', 'Task Assigned'), 

11 ('TASK_DUE_SOON', 'Task Due Soon'), 

12 ('CHAT_MENTION', 'Chat Mention'), 

13 ('CHAT_DM', 'Chat Direct Message'), 

14 ('MEMBER_INVITED', 'Member Invited'), 

15 ('SYSTEM_ALERT', 'System Alert'), 

16 ] 

17 

18 recipient = models.ForeignKey(User, on_delete=models.CASCADE, related_name='notifications') 

19 type = models.CharField(max_length=32, choices=TYPE_CHOICES, default='SYSTEM_ALERT') 

20 title = models.CharField(max_length=255) 

21 message = models.TextField() 

22 link_url = models.CharField(max_length=255, blank=True, null=True) 

23 is_read = models.BooleanField(default=False) 

24 read_at = models.DateTimeField(blank=True, null=True) 

25 

26 class Meta: 

27 ordering = ['-created_at'] 

28 

29 def __str__(self): 

30 return f"{self.title} for {self.recipient.email}"