Django how to update boolean value of an objects in class based views?

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

A great couple of resources for understanding the flow of the Generic CBVs is the Classy Class-Based view site and the CBV Diagrams page.

Your function is fine, although you probably don’t need to capture the results of the update operation nor return it from your function. What you need to do is identify an appropriate location to either call that function or directly update the Notifications. You could probably do that in the get_context_data method. (That seems to me to be as appropriate a place as any.)

Thanks KenWhitesell. After pass it in get_context_data it worked and also thanks for the helpful link.