Thursday, July 1, 2021

paginate_by attribute not giving error.

Hello guys, it's been a while here.

Need some help pls.

I had to override my ListView get_querryset() method to query my posts according to a given category. But it seem my context is not a list of objects again as I get this error message: "TypeError: unhashable type: 'slice' " when I try to add a paginate_by attribute to the view. Pls see my view below:



class CategoryListView(ListView):
    template_name = 'blog/category.html'
    context_object_name = 'cat_list'
    paginate_by = 4

    def get_queryset(self):
        context = {
            'cat': self.kwargs['category'],
            'posts': Post.objects.filter(category__name=self.kwargs['category'], status='published')
        }
        return context

Any help will be appreciated as I don't seem to be strong with Django.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALcuGNsa7gbpS7%3D_8tUNpXUVduR8tshygU7ZZNco1gjUz%3DeJTg%40mail.gmail.com.

No comments:

Post a Comment