title: models.Meta.ordering vs ModelAdmin.ordering &ndash; How to reclaim performance after Meta.ordering test?
body: <p><strong>Setup</strong></p>
  
  <p>I had two Django (1.4.2) models like so:</p>
  
  <pre><code>class CoreData(models.Model):
     cdid = models.AutoField(primary_key=True,editable=False)
     name = models.CharField(max_length=100,db_index=True,unique=True)
     # etc
  
  class DetailData(models.Model):
      cdid = models.OneToOneField(CoreData,primary_key=True)
      detl = models.CharField(max_length=100)
      # etc
  </code></pre>
  
  <p>And the following admin definitions:</p>
  
  <pre><code>class CoreDataAdmin(admin.ModelAdmin):
      ordering = ['name']
      readonly_fields = ('etc', )
  admin.site.register(CoreData, CoreDataAdmin)
  
  class DetailDataAdmin(admin.ModelAdmin):
      ordering = ['cdid__name']
      readonly_fields = ('etc', )
  admin.site.register(DetailData, DetailDataAdmin)
  </code></pre>
  
  <p>In Django's admin interface, this leads to the intended sorting in the overviews for <code>CoreData</code> and <code>DetailData</code>, in other words, both lists are sorted in ascending order of the <code>CoreData</code> <code>name</code> field.</p>
  
  <p>However, what's <em>not</em> sorted is the pulldown list on the <code>DetailData</code> entry page. It's listed in ascending <code>cdid</code> order.</p>
  
  <p>There comes a day when you want to change this.</p>
  
  <p>For reasons outside the scope of this simplified illustration, I extended the models like so:</p>
  
  <pre><code>class CoreData(models.Model):
      cdid = models.AutoField(primary_key=True,editable=False)
      name = models.CharField(max_length=100,db_index=True,unique=True)
      # etc
      class Meta:
          ordering = ['name']
  
  class DetailData(models.Model):
      cdid = models.OneToOneField(CoreData,primary_key=True)
      detl = models.CharField(max_length=100)
      # etc
      class Meta:
          ordering = ['cdid__name']
  </code></pre>
  
  <p>And I believe I left the <code>ordering</code> in the admin definition in place for my first test.</p>
  
  <p><strong>Observation</strong></p>
  
  <p>The changes I made have led to increased processing times on the Django test server (by order of magnitude). This is the case <em>even for the item overview page</em>. I've even seen broken pipes (due to browser retries I'd say) where there was almost no delay before the modification. All CPU cores remain unimpressed; presumably the slowdown happens due to dramatically increased database requests. (We're not talking about tens of thousands of DB records here, and besides, the admin item overview page, which is affected, shows a limited number of items.)</p>
  
  <p>So far, so good: <em>If only I could revert that effect</em>. But even changing back to the original definitions does not improve the situation.</p>
  
  <p><strong>Questions</strong></p>
  
  <ul>
  <li>How can I get back the "old" performance of the test server? Where do I need to clean up? I've reverted to the original definitions and tried (with not much hope, but who knows) some <code>manage.py</code> commands without any results. The DB structure remains unaffected; nothing changed there.</li>
  <li>Is there a piece of documentation on how the two <code>ordered</code> mechanisms are supposed to interoperate? Haven't found that so far.</li>
  <li>What other experience do you have with this, or is everybody simply using the <a href="https://stackoverflow.com/a/1474175"><code>ModelForm</code>, 'ModelChoiceField' and <code>queryset</code> approach</a>?</li>
  </ul>