title: Django query: Sort objects by the number of occurrences of a value?
body: <p>I'm trying to use Django to return a list of objects with duplicate values, sorted from most-duplicated to least-duplicated.</p>
  
  <p>For example, let's say I have the following model:</p>
  
  <pre class="lang-py prettyprint-override"><code>class Person(models.Model):
      id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
      name = models.CharField(max_length=128)
  </code></pre>
  
  <p>I want to return a list of <code>Person</code>s, sorted from those with the most common <code>name</code> to those with the least common <code>name</code>.</p>
  
  <p>I know that I can use <code>values</code> and <code>annotate</code> to create a sorted list of <code>name</code> values like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>Person.values('name').annotate(Count('id')).order_by('id__count')
  </code></pre>
  
  <p>But I don't want a list of <code>name</code>s; I want a list of <code>Person</code> objects. Is there a way to accomplish this?</p>