Friday, July 2, 2021

Re: paginate_by attribute not giving error.

override `get_context_data` instead of `get_queryset` for this task
refer: https://ccbv.co.uk/

On Thu, 1 Jul 2021 at 14:41, sunday honesty <honesty202616@gmail.com> wrote:
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.

--
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/CAGp2JVF%3D8VO1vzEAPWVHRRf4z4G4ue1SQqVsfyYTU3p189TjRA%40mail.gmail.com.

No comments:

Post a Comment