first push
This commit is contained in:
151
notification/models.py
Normal file
151
notification/models.py
Normal file
@@ -0,0 +1,151 @@
|
||||
from django.db import models
|
||||
|
||||
from authentication.models import BaseModel
|
||||
from authentication.models import UserProfile, Group
|
||||
|
||||
|
||||
# from numpy import char
|
||||
|
||||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class NotificationActions(BaseModel):
|
||||
name = models.CharField(max_length=100, default="", null=True)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(NotificationActions, self).save(*args, **kwargs)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class NotificationButton(BaseModel):
|
||||
content = models.CharField(max_length=20, default="", null=True)
|
||||
order = models.IntegerField(default=0, null=True)
|
||||
action = models.ForeignKey(
|
||||
NotificationActions,
|
||||
on_delete=models.CASCADE,
|
||||
default=None,
|
||||
null=True,
|
||||
related_name="btn_actions",
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.content
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(NotificationButton, self).save(*args, **kwargs)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
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(UserProfile, on_delete=models.CASCADE, related_name="notification_user", 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",
|
||||
)
|
||||
notif_action = models.ForeignKey(
|
||||
NotificationActions,
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
default=None,
|
||||
related_name="actions",
|
||||
)
|
||||
notif_button = models.ForeignKey(
|
||||
NotificationButton,
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
default=None,
|
||||
related_name="buttons",
|
||||
)
|
||||
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)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.title
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Notification, self).save(*args, **kwargs)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class DashboardNotification(BaseModel):
|
||||
role = models.ManyToManyField(Group,
|
||||
null=True,
|
||||
related_name="dashboard_notification")
|
||||
title = models.CharField(max_length=250, null=True)
|
||||
text = models.TextField(null=True)
|
||||
date = models.DateTimeField(null=True)
|
||||
status = models.CharField(max_length=100, null=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(DashboardNotification, self).save(*args, **kwargs)
|
||||
Reference in New Issue
Block a user