0

如何设计“消息已读”功能?

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()
4

1 回答 1

1

添加到私人消息

is_read = models.BooleanField(default=False)

如果“to_user”进入视图,您可以检查:

if user == pm.to_user and not pm.is_read:
    pm.is_read = True
    pm.save()
于 2012-10-23T09:53:53.713 回答