25 lines
904 B
Python
25 lines
904 B
Python
from django.db import models
|
|
from django.conf import settings
|
|
from tenants.managers import TenantScopedManager
|
|
from tenants.models import Tenant
|
|
|
|
class Notification(models.Model):
|
|
tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE, related_name='notifications')
|
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='notifications')
|
|
title = models.CharField(max_length=255)
|
|
message = models.TextField()
|
|
is_read = models.BooleanField(default=False)
|
|
link = models.URLField(max_length=500, null=True, blank=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
objects = TenantScopedManager()
|
|
|
|
class Meta:
|
|
ordering = ['-created_at']
|
|
indexes = [
|
|
models.Index(fields=['tenant', 'user', 'is_read']),
|
|
]
|
|
|
|
def __str__(self):
|
|
return f"Notification for {self.user}: {self.title}"
|