title: Get distinct values of Queryset by field
body: <p>I've got this model:</p>
  
  <pre><code>class Visit(models.Model):
      timestamp  = models.DateTimeField(editable=False)
      ip_address = models.IPAddressField(editable=False)
  </code></pre>
  
  <p>If a user visits multiple times in one day, <strong><em>how can I filter for unique rows based on the ip field?</em></strong> (I want the unique visits for today)</p>
  
  <pre><code>today = datetime.datetime.today()
  yesterday = datetime.datetime.today() - datetime.timedelta(days=1)
  
  visits = Visit.objects.filter(timestamp__range=(yesterday, today)) #.something?
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I see that I can use:</p>
  
  <pre><code>Visit.objects.filter(timestamp__range=(yesterday, today)).values('ip_address')
  </code></pre>
  
  <p>to get a ValuesQuerySet of just the ip fields. Now my QuerySet looks like this:</p>
  
  <pre><code>[{'ip_address': u'127.0.0.1'}, {'ip_address': u'127.0.0.1'}, {'ip_address':
   u'127.0.0.1'}, {'ip_address': u'127.0.0.1'}, {'ip_address': u'127.0.0.1'}]
  </code></pre>
  
  <p><strong>How do I filter this for uniqueness without evaluating the QuerySet and taking the db hit?</strong> </p>
  
  <pre><code># Hope it's something like this...
  values.distinct().count()
  </code></pre>