如何设计功能“消息已被阅读”?
class UserProfil(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=50)
class PrivateMessage(models.Model):
from_user = models.OneToOneField(User)
to_user = models.OneToOneField(User)
date = models.DateTimeField(auto_now_add=True)
content = models.TextField()
答案 0 :(得分:1)
添加到PrivateMessage
is_read = models.BooleanField(default=False)
如果“to_user”进入视图,您可以检查:
if user == pm.to_user and not pm.is_read:
pm.is_read = True
pm.save()