[Solved]-Django AttributeError Model object has no attribute 'filter'

19👍

def get_queryset(self):
    ...

    return Article.objects.filter(created_at__startswith=publication_date, slug=self.kwargs.get("pk", None))

Because get_queryset must return QuerySet object, not model one

0👍

you can also use get_object()

def get_object(self):
    ...

    return Article.objects.get(created_at__startswith=publication_date, slug=self.kwargs.get("pk", None))

Leave a comment