DEV Community

loading...

Discussion on: How to track number of hits/views for particular objects in Django | Django Packages Series #2

Collapse
soniarpit profile image
CodeSnail 🐌
class PostDetail(HitCountDetailView):
    model = Post
    context_object_name = "post"
    template_name = "awesomeposts/post_detail.html"
    count_hit = True

    def get_object(self):
        username = self.kwargs.get("username")
        post = self.kwargs.get("post")
        return get_object_or_404(
            Post,
            user=User.objects.get(username=username),
            slug=post,
        )
Enter fullscreen mode Exit fullscreen mode

do like this

Thread Thread
ybastan profile image
ybastan

I don't know why but it didn't worked for me. Still 0 (zero)