Reputation: 385
How to design function "message was read" ?
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()
Upvotes: 0
Views: 57
Reputation: 54
add to PrivateMessage
is_read = models.BooleanField(default=False)
and if the "to_user" get into the view, you can check like:
if user == pm.to_user and not pm.is_read:
pm.is_read = True
pm.save()
Upvotes: 1