title: Django hit counts Class-based views
body: <p>I'm trying to do something like youtube views:</p>
  
  <pre><code>models.py
  class Video(models.Model):
      title = models.CharField(max_length=100)
      embed = models.TextField
      created_at = models.DateTimeField(auto_now_add=True,editable=False)
      updated_at = models.DateTimeField(auto_add=True,editable=False)
      visit_count = models.IntegerField(default=0)
  
      def add_visit(self):
          if self.visit_count is not None:
              self.visit_count += 1
          else:
              self.visit_count = 0
  
  views.py
  class VideoDetail(DetailView):
      model = Video
  
      def get_context_data(self, **kwargs):
          context = super(VideoDetail, self).get_context_data(**kwargs)
          self.object.add_visit()
          self.object.save()
          return context
  
  Example use:
      Video.objects.order_by('-visit_count')
  </code></pre>
  
  <p>So is everything working properly, but not quite, as I can count limit by IP.</p>
  
  <pre><code>class Video(models.Model):
      title = models.CharField(max_length=100)
      embed = models.TextField
      created_at = models.DateTimeField(auto_now_add=True,editable=False)
      updated_at = models.DateTimeField(auto_add=True,editable=False)
  
  class Visit(models.Model):
      video = models.ForeignKey(Video)
      ip = models.IPAddressField()
      visit_count = models.IntegerField(default=0)
  </code></pre>
  
  <p>How to insert in views or models: visit_count,ip,video.</p>