title: Django selecting a count
body: <p>I'm fairly new to Django and I want to get the total clients a user has (my users will be selling something through my website) so I have a table called orders where I keep the <code>user_id</code> of the user who purchased and the <code>product_id</code> being purchased. Each product id is related to a product that has a user (the one I'm doing the query for):</p>
  
  <pre><code>select COUNT(distinct(o.user_id)) as total_clients from `order` o 
      inner join product p on p.id=o.product_id where p.user_id=32;
  </code></pre>
  
  <p>User id <code>32</code> is logged in and I want to show him how many clients purchased his products.</p>
  
  <p>I want to do this in a <code>get</code> instead of <code>filter</code> as it makes more sense.</p>
  
  <p>Here's what my logic tells me to write:</p>
  
  <pre><code>clients = Order.objects.get(
      status = Order.COMPLETED,
      product__user = self.user
  ).annotate(
      total_clients = Count( 'user', distinct = True )
  )
  
  return clients.total_clients
  </code></pre>
  
  <p>.and here's what it returns:</p>
  
  <pre><code>Exception Type: MultipleObjectsReturned
  Exception Value:  get() returned more than one Order -- it returned 2!
  </code></pre>
  
  <p>I could probably be running a query instead of using the orm but I don't want that. This is a rather simple query that I'm sure Django is handling very easily and I want to keep away from writing strings in my code.</p>
  
  <p>Here's my model setup:</p>
  
  <pre><code>class UserProfile( models.Model ):
      user = models.OneToOneField( User, related_name = 'profile' )
      ....
  
  
      def get_total_clients( self ):
          clients = Order.objects.get(
              status = Order.COMPLETED,
              product__user = self.user
          ).annotate(
              total_clients = Count( 'user', distinct = True )
          )
  
          return clients.total_clients
  
  
  class Order( models.Model ):
      PENDING = 0
      COMPLETED = 1
      REFUNDED = 2
  
      STATUS_CHOICES = (
          (PENDING, "Pending"),
          (COMPLETED, "Completed"),
          (REFUNDED, "Refunded"),
      )
  
      user = models.ForeignKey( User, related_name = "orders" )
      product = models.ForeignKey( Product, related_name = "orders" )
      amount = models.DecimalField( max_digits = 6, decimal_places = 2, default = 0.00 )
      status = models.SmallIntegerField(
          choices = STATUS_CHOICES, default = PENDING, db_index = True
      )
  
  
  class Product( models.Model ):
      user = models.ForeignKey( User, related_name = "unlocks" )
      name = models.CharField( max_length = 255 )
  </code></pre>