22 lines
664 B
Python
Executable File
22 lines
664 B
Python
Executable File
# notifications_app/models.py
|
|
from django.db import models
|
|
from django.conf import settings
|
|
|
|
class Notification(models.Model):
|
|
recipient = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="notifications"
|
|
)
|
|
message = models.TextField()
|
|
is_read = models.BooleanField(default=False)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
is_archived = models.BooleanField(default=False)
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|
|
|
|
def __str__(self):
|
|
return f"To {self.recipient} - {self.message[:30]}"
|
|
|
|
def soft_delete(self):
|
|
self.is_archived = True
|
|
self.save() |