title: Order by count of related model in django?
body: <p>I'm trying to order a queryset by the count of another model that queryset relates to.</p>
  
  <pre><code>class Post(models.Model):
      ...
  
  class PostView(models.Model):
      post = models.ForeignKey(Post, related_name="post_views")
  </code></pre>
  
  <p>Now, I would assume that this would work:</p>
  
  <pre><code>Post.objects.all().order_by('post_views')
  </code></pre>
  
  <p>But I get this error:</p>
  
  <blockquote>
    <p>AttributeError at /api/posts/?order_by=views</p>
    
    <p>'ManyToOneRel' object has no attribute 'attname'</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>