title: Django search counter
body: <p>Hi I have an application which checks and counts searched terms by updating a counter if the query has already been searched and inserts a field with counter=1 if the query is new. </p>
  
  <p>The search counter model:</p>
  
  <pre><code>class Search(models.Model):
      term = models.CharField(unique=True, max_length=255)
      counter = models.IntegerField()
      last_search = models.DateTimeField()
  </code></pre>
  
  <p>and a view containing this:</p>
  
  <pre><code># update search counter with term
      try:        
          term = Search.objects.get(term=query)
      except Search.DoesNotExist:
          term = None
      if term:
          term.counter = F('counter') + 1
          term.last_search = datetime.now()
      else:
          term = Search(
                  term=query,
                  counter=1,
                  last_search = datetime.now()
          )               
      term.save()
  </code></pre>
  
  <p>My question is really - is this a good way to do this and is there a more concise way to put it? It seems overly ugly to me, and being a Django novice I would like to see a 'best practice' implementation of the same. Any answers appreciated.</p>