-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
用户通知系统设计 #6
Comments
通知消息的数据模型设计思路通知的数据模型参考
Django 中泛型外键在上面的示例中,我们事件动作结果对应的是不同实体的。一个对应“主题",一个对应 "回复" action_object_content_type = models.ForeignKey(ContentType, blank=True, null=True,
related_name='notify_action_object', on_delete=models.CASCADE)
action_object_object_id = models.CharField(max_length=255, blank=True, null=True)
action_object = GenericForeignKey('action_object_content_type', 'action_object_object_id')
数据模型的基本实现命名对应如下:
class Notification(BaseModel):
"""通知 模型设计参考自 django-notifications"""
recipient = models.ForeignKey(WepostUser, on_delete=models.CASCADE, verbose_name="接收人")
# django-notifications 中的 verb 一内容就体现在 category 中.
category = models.BigIntegerField("类别", choices=NotificationCategory.choices())
level = models.PositiveSmallIntegerField("级别", choices=NotificationLevel.choices(), default=NotificationLevel.INFO)
unread = models.BooleanField("未读", db_index=True,default=True)
# 配置泛型 actor 外键关联
actor_content_type = models.ForeignKey(ContentType, blank=True, null=True, related_name="notify_actor",
on_delete=models.CASCADE)
actor_object_id = models.CharField(max_length=255, blank=True, null=True)
actor = GenericForeignKey('actor_content_type', 'actor_object_id')
# 配置事件发生范围,如果是指发帖子的话,可以认为是关联到对应节点.
target_content_type = models.ForeignKey(
ContentType,
related_name='notify_target',
blank=True,
null=True,
on_delete=models.CASCADE
)
target_object_id = models.CharField(max_length=255, blank=True, null=True)
target = GenericForeignKey('target_content_type', 'target_object_id')
# 配置事件发生主体,以发贴来说,可以当作关联到具体的帖子
action_object_content_type = models.ForeignKey(ContentType, blank=True, null=True,
related_name='notify_action_object', on_delete=models.CASCADE)
action_object_object_id = models.CharField(max_length=255, blank=True, null=True)
action_object = GenericForeignKey('action_object_content_type', 'action_object_object_id')
memo = models.TextField("备注", blank=True, null=True, help_text="可以用来保存简短的回复等内容") |
在用户创建的主题回收回复,收到感谢,或者在一些回复中被
@
了。需要通知用户。数据模型设计
当前的通知类型有如下一些:
@
通知消息类别与位操作
这些用户又有不同的重要程度,用户应该可以忽略不重要的消息。
由于这些消息种类不是特别多。可以使用位运算方便后面操作与查询 。
使用 64 位的整型存储可以支持最多64种不同类型的通知。对于此类系统来说完全足够了。
一个用户要面对 64 个开关也是够了。
当前针对上面的通知类型,细化声明如下:
The text was updated successfully, but these errors were encountered: