DEV Community

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

Collapse
 
samatuulu profile image
Beka

How I can get the number views of one object in django shell?
I am getting error that says:
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'GenericRelatedObjectManager' object has no attribute 'hits'

for this error the query is: john_wick.hit_count_generic.hits

john_wick is Movie instance. And my model is

class Movie(models.Model):
title = models.CharField(max_length=100)
description = models.TextField(max_length=2000)
image = models.ImageField(upload_to='movie_upload', null=False, blank=False)
year_of_production = models.IntegerField()
iframe = models.CharField(max_length=1500, verbose_name='iframe src')
hit_count_generic = GenericRelation(HitCount, object_id_field='object_pk',
related_query_name='hit_count_generic_relation')
created_at = models.DateTimeField(auto_now_add=True)

Please help me figure out.