In function based views I am using this code Notifications.objects.filter(receiver=user, is_seen=False).update(is_seen=True)
for update an objects status from False to True. How to do that in class based view:
here is my code:
class ListNoti(ListView):
model = Notifications
template_name = 'notifications/notifications.html'
def get_context_data(self, **kwargs):
data = super(ListNoti,self).get_context_data(**kwargs)
data['author_noti'] = Notifications.objects.filter(receiver=self.request.user,duplicate_value="author").order_by('-date')
data['commenter_noti'] = Notifications.objects.all().filter(sender=self.request.user,duplicate_value="commenter").order_by('-date')
return data
I also tried this code in my class based view but didn’t work.
def update_noti_status(self, *args, **kwargs):
noti = Notifications.objects.filter(is_seen=False).update(is_seen=True)
return noti