title: Track the number of "page views" or "hits" of an object?
body: <p>I am sure that someone has a pluggable app (or tutorial) out there that approximates this, but I have having trouble finding it: I want to be able to track the number of &quot;views&quot; a particular object has (just like a question here on stackoverflow has a &quot;view count&quot;).</p>
  <p>If the user isn't logged in, I wouldn't mind attempting to place a cookie (or log an IP) so they can't inadvertently run up the view count by refreshing the page; and if a user is logged in, only allow them one &quot;view&quot; across sessions/browsers/IP addresses. I don't think I need it any fancier than that.</p>
  <p>I figure the best way to do this is with Middleware that is decoupled from the various models I want to track and using an F expression (of sorts) -- other questions on StackOverflow have alluded to this (<a href="https://stackoverflow.com/questions/622652/incremement-page-hit-count-in-django">1</a>), (<a href="https://stackoverflow.com/questions/888905/django-counting-model-instance-views-for-a-top-entries-app/891100#891100">2</a>), (<a href="https://stackoverflow.com/questions/1212559/spam-proof-hit-counter-in-django">3</a>).</p>
  <p>But I wonder if this code exists out in the wild already -- because I am not the savviest coder and I'm sure someone could do it better.  Smile.</p>
  <p>Have you seen it?</p>