# Django 'int' object is not iterable when trying to update objects in views

**URL:** <https://forum.djangoproject.com/t/django-int-object-is-not-iterable-when-trying-to-update-objects-in-views/11817>\
**Category:** Using Django\
**Created:** [January 26, 2022, 7:43pm UTC](https://forum.djangoproject.com/t/django-int-object-is-not-iterable-when-trying-to-update-objects-in-views/11817 "2022-01-26T19:43:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MDFARHYN](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mdfarhyn/32/4519_2.png) [@MDFARHYN](https://forum.djangoproject.com/u/MDFARHYN)\
**Post date:** [January 26, 2022, 7:43pm UTC](https://forum.djangoproject.com/t/django-int-object-is-not-iterable-when-trying-to-update-objects-in-views/11817/1 "2022-01-26T19:43:57Z")

</div>

I am getting error when trying to update objects from False to True. here is my code:

```auto
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`

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 26, 2022, 7:55pm UTC](https://forum.djangoproject.com/t/django-int-object-is-not-iterable-when-trying-to-update-objects-in-views/11817/2 "2022-01-26T19:55:26Z")

</div>

Please post the complete error traceback from the console, along with your Notifications model and the notifications.html template.

---

<div class="post-metadata">

**Author:** ![MDFARHYN](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mdfarhyn/32/4519_2.png) [@MDFARHYN](https://forum.djangoproject.com/u/MDFARHYN)\
**Post date:** [January 26, 2022, 8:16pm UTC](https://forum.djangoproject.com/t/django-int-object-is-not-iterable-when-trying-to-update-objects-in-views/11817/4 "2022-01-26T20:16:18Z")

</div>

[KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell) I solved this issue after using queryset in my views. here is my full code:

```auto
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`?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 26, 2022, 9:22pm UTC](https://forum.djangoproject.com/t/django-int-object-is-not-iterable-when-trying-to-update-objects-in-views/11817/5 "2022-01-26T21:22:42Z")

</div>

The filter was working fine, the problem was somewhere else.

You need to be aware of the data type being returned by functions being called, and pay attention to what data type you need to return from a function.
