1👍
✅
The simplest approach would be:
Have a field in the models for viewed_at
which is nullable. Once viewed, set the date. If no value is set, that means the user has not viewed it yet.
If there are multiple users whom this feature needs to be extended to, have a foreign key reference:
class MyViewableObject(models.Model):
#fields
class MyViewableViewedBy(models.Model):
user = models.ForeignKey(User)
viewable = models.ForeignKey(MyViewableObject)
Now, when MyViewableObject
is viewed, in the view method, create an association for the request.user
in the MyViewableViewedBy
model.
The user has not viewed if there is no corresponding user entry for the object in the model MyViewableViewedBy
Source:stackexchange.com