Answer the question
In order to leave comments, you need to log in
How to make a view counting system?
Hello everyone
Task: the site has a lot (several thousand products), you need to first develop a system for recording views - i.e. which product is viewed more, which less, etc. This will then be used for various recommendation systems.
What is the best way to count views?
Answer the question
In order to leave comments, you need to log in
Make a url counter that is inserted into the page as empty <script src="/mycounter">
. Firstly, bots usually don't load scripts, and secondly, it's very simple. And thirdly, most likely the browser has already loaded the page.
Don't forget to give a non-cached header, otherwise the browser will load your empty counter once and won't load it again.
Good afternoon, we have implemented this field in the product model:
In the product view class (we have DetailView), the get_object method is overridden:
def get_object(self, queryset=None):
self.object = super(DetailViewPageView, self).get_object()
self.object.show_count += 1
self.object.save()
return self.object
1. downloaded https://freegeoip.net/json/
on the client
2. if there is none in the database, add its ip to the database and make +1 view.
3. if there is in the database, then we are glad to see you again on our website :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question