title: How to sort by many custom methods in Django Admin
body: <p>I want to be able to sort by several custom methods in Django Admin. <a href="https://stackoverflow.com/questions/2168475/django-admin-how-to-sort-by-one-of-the-custom-list-display-fields-that-has-no-d">This question</a> provides solution for one method only.</p>
  
  <p>I tried to modify it:</p>
  
  <pre><code>from django.db import models
  
  class CustomerAdmin(admin.ModelAdmin):
      list_display = ('number_of_orders','number_of_somevalue') # added field
  
      def queryset(self, request):
          qs = super(CustomerAdmin, self).queryset(request)
          qs = qs.annotate(models.Count('order'))
          qs = qs.annotate(models.Count('somevalue')) # added line
          return qs
  
      def number_of_orders(self, obj):
          return obj.order__count
      number_of_orders.admin_order_field = 'order__count'
  
      def number_of_somevalue(self, obj): # added method
          return obj.somevalue__count
      number_of_somevalue.admin_order_field = 'somevalue__count'
  </code></pre>
  
  <p>and it works incorrectly. It seems that it multiplies the <code>count</code> values instead of counting them separately.</p>
  
  <p>Example:</p>
  
  <p>I have 2 orders and 2 somevalues, but in the panel I see 4 orders and 4 somevalues.</p>
  
  <p>Adding another method with yet another value makes it 8 (2*2*2).</p>
  
  <p>How can I fix it?</p>