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