2021-05-31 09:20:38 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2022-04-07 10:51:35 +00:00
|
|
|
from common.db.models import JMSBaseModel
|
2021-05-31 09:20:38 +00:00
|
|
|
|
2023-02-01 08:43:43 +00:00
|
|
|
__all__ = ('SiteMessage', 'MessageContent')
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
|
2023-02-01 08:43:43 +00:00
|
|
|
class SiteMessage(JMSBaseModel):
|
|
|
|
content = models.ForeignKey('notifications.MessageContent', on_delete=models.CASCADE,
|
|
|
|
db_constraint=False, related_name='messages')
|
|
|
|
user = models.ForeignKey('users.User', on_delete=models.CASCADE, db_constraint=False)
|
2021-05-31 09:20:38 +00:00
|
|
|
has_read = models.BooleanField(default=False)
|
|
|
|
read_at = models.DateTimeField(default=None, null=True)
|
2022-12-20 12:23:42 +00:00
|
|
|
comment = ''
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
|
2023-02-01 08:43:43 +00:00
|
|
|
class MessageContent(JMSBaseModel):
|
2021-05-31 09:20:38 +00:00
|
|
|
subject = models.CharField(max_length=1024)
|
|
|
|
message = models.TextField()
|
|
|
|
users = models.ManyToManyField(
|
2023-02-01 08:43:43 +00:00
|
|
|
'users.User', through=SiteMessage,
|
|
|
|
related_name='recv_site_messages'
|
2021-05-31 09:20:38 +00:00
|
|
|
)
|
|
|
|
groups = models.ManyToManyField('users.UserGroup')
|
|
|
|
is_broadcast = models.BooleanField(default=False)
|
|
|
|
sender = models.ForeignKey(
|
|
|
|
'users.User', db_constraint=False, on_delete=models.DO_NOTHING, null=True, default=None,
|
|
|
|
related_name='send_site_message'
|
|
|
|
)
|
2022-12-20 12:23:42 +00:00
|
|
|
comment = ''
|
2021-05-31 09:20:38 +00:00
|
|
|
|
|
|
|
has_read = False
|
|
|
|
read_at = None
|