I am trying to count likes on each item in my blog. But i am getting this error
method’ object does not support item assignment
My Model
likes = models.ManyToManyField(User, related_name=‘blog_posts’)
def total_likes(self):
return self.likes.count()
Views
class ItemDetailView(DetailView):
model = Item
template_name =‘waqart/item_detail.html’
#function to count total likes the main total_likes function is detail inside model
def get_context_data(self, *args, **kwargs):
context = super(ItemDetailView, self).get_context_data
stuff = get_object_or_404(Item, id=self.kwargs['pk'])
total_likes = stuff.total_likes()
context['total_likes']= total_likes
return context