I am getting error when trying to update objects from False to True. here is my code:
class ListNoti(LoginRequiredMixin,ListView):
raise_exception = True
model = Notifications
template_name = 'notifications/notifications.html'
def get_context_data(self, **kwargs):
data = super(ListNoti,self).get_context_data(**kwargs)
data['noti'] = Notifications.objects.filter(receiver=self.request.user,is_seen=False).order_by('-date').update(is_seen=True)
return data
.update(is_seen=True)
raising this error TypeError at /notification/ 'int' object is not iterable
KenWhitesell I solved this issue after using queryset in my views. here is my full code:
class ListNoti(LoginRequiredMixin,ListView):
raise_exception = True
model = Notifications
template_name = 'notifications/notifications.html'
def get_queryset(self):
data = Notifications.objects.filter(receiver=self.request.user).update(is_seen=True)
return data
def get_context_data(self, **kwargs):
data = super(ListNoti,self).get_context_data(**kwargs)
data['noti'] = Notifications.objects.filter(receiver=self.request.user)
return data
I am not understanding why filter was not working in get_context_data
?