title: Is it possible to order_by with a callable?
body: <p><strong>DUPLICATE:</strong> <a href="https://stackoverflow.com/questions/981375/using-a-django-custom-model-method-property-in-orderby">Using a Django custom model method property in order_by()</a></p>
  
  <p>I have two models;  one that stores posts and another that stores votes made on those posts, related using a ForeignKey field.  Each vote is stored as a separate record since I need to track the user and datetime that the vote was cast.</p>
  
  <p>I've created a helper function that tallys all the votes using the Django 1.1 aggregation Sum function.</p>
  
  <pre><code>class Post(models.Model):
      ...some fields...
  
      def tally(self):
          return self.vote_set.all().aggregate(Sum('value'))['value__sum'] or 0
  
  class Vote(models.Model):
      post = models.ForeignKey(Post)
      value = models.IntegerField()
      ...some fields...
  </code></pre>
  
  <p>One query I need to make needs to do a one off <code>order_by</code> of the tally.  However:</p>
  
  <pre><code>Post.objects.all().order_by('tally')
  </code></pre>
  
  <p>yields the following template error:</p>
  
  <blockquote>
    <p>Caught an exception while rendering:
    Cannot resolve keyword 'tally' into
    field. Choices are: date_created,
    description, id, is_active, name,
    related, slug, user, vote</p>
  </blockquote>
  
  <p>It there any way to get the <code>order_by()</code> function to take a callable?</p>