Files
Rasadyar_Users/Notification/models.py
2026-01-18 12:05:56 +03:30

90 lines
2.7 KiB
Python

from django.contrib.auth.models import User, Group
from Core.models import BaseModel
from django.db import models
# Create your models here.
class NotificationType(BaseModel):
notif_types = (
("user", "USER"),
("alluser", "AllUSER"),
("group", "GROUP"),
("allgroup", "AllGROUP"),
("usergroup", "UserGroup"),
("poultry", "Poultry"),
("province_accept", "ProvinceAccept"),
("province_rejected", "ProvinceRejected"),
("city_operator_accept", "CityOperatorAccept"),
("city_operator_rejected", "CityOperatorRejected"),
("assignment_accepted", "AssignmentAccepted"),
("assignment_rejected", "AssignmentRejected"),
)
name = models.CharField(choices=notif_types, max_length=50, default="", null=True)
def __str__(self) -> str:
return self.name
def save(self, *args, **kwargs):
super(NotificationType, self).save(*args, **kwargs)
pass
class NotificationToken(BaseModel):
token = models.CharField(max_length=100)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="notification_user", null=True)
app_name = models.CharField(max_length=100, null=True)
def __str__(self) -> str:
return self.token
def save(self, *args, **kwargs):
super(NotificationToken, self).save(*args, **kwargs)
pass
class Notification(BaseModel):
s = (
("read", "Read"),
("pending", "Pending"),
("sent", "Sent"),
("unread", "Unread"),
("silent", "Silent"),
)
notif_type = models.ForeignKey(
NotificationType,
on_delete=models.CASCADE,
null=True,
default=None,
related_name="types",
)
notification_user = models.ManyToManyField(
NotificationToken,
null=True,
related_name="notification_token"
)
notification_group = models.ManyToManyField(
Group,
null=True,
related_name="group"
)
title = models.CharField(max_length=200, default="", null=True)
content = models.CharField(max_length=500, default="", null=True)
image = models.CharField(max_length=100, null=True)
icon = models.CharField(max_length=100, null=True)
app_ids = models.CharField(max_length=200, default="", null=True)
device_ids = models.CharField(max_length=200, default="", null=True)
hash_id = models.CharField(max_length=20, default="", null=True)
status = models.CharField(choices=s, max_length=10, default="", null=True)
app_name = models.CharField(max_length=100, null=True)
def __str__(self) -> str:
return self.title
def save(self, *args, **kwargs):
super(Notification, self).save(*args, **kwargs)
pass