#StackBounty: #python #django #django-views How to add IP to 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)

    def __str__(self):
        return self.title

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

Here is the views.py

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

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

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