paginate_by attribute not giving error.

53 views
Skip to first unread message

sunday honesty

unread,
Jul 1, 2021, 5:11:44 AM7/1/21
to django...@googlegroups.com
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.

Lalit Suthar

unread,
Jul 2, 2021, 9:23:30 AM7/2/21
to django...@googlegroups.com
override `get_context_data` instead of `get_queryset` for this task
refer: https://ccbv.co.uk/

--
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...@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.
Reply all
Reply to author
Forward
0 new messages