Объект Django 'int' не является итерируемым при попытке обновить объект
Я получаю эту ошибку при попытке обновить объекты с false на True. вот мой код:
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) вызывает эту ошибку TypeError at /notification/ 'int' object is not iterable
Я решил эту проблему после использования queryset в моих представлениях. вот мой полный код:
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