#StackBounty: #python #django #django-views Creating a Page Visitor Count for Detail View in Django

Bounty: 50

I am trying to collect data for each visitor count related to every Page View Detail.

I have implemented the function which counts the visitors for the page but everytime it is refreshed it will add one more view which is not accurate data. My question is how to add to the function IP adress to show if it does exist the disregard it from the count and the visitor count is only related to new visitors.

Here is the models.py

class Post(models.Model):
    user= models.ForeignKey(User, on_delete=models.CASCADE)
    --------------------------------------------------
    title = models.CharField(max_length=100, unique=True)
    viewCount=models.IntegerField(default=0)

    def __str__(self):
        return self.title

    def incrementViewCount(self):
        self.viewCount += 1
        self.save()

Here is the views.py

    def get(self, request, *args, **kwargs):
        res = super().get(request, *args, **kwargs)
        self.object.incrementViewCount()
        return res


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.