title: Django admin inline: select_related
body: <p>Using Django 1.8 on Python 3.4.1 with models:</p>
  
  <pre><code>class Product(models.Model):
      name = models.CharField(max_length=255)
      # some more fields here
  
      def __str__(self):
          return self.name
  
  
  class PricedProduct(models.Model):
      product = models.ForeignKey(Product, related_name='prices')
      # some more fields here
  
      def __str__(self):
          return str(self.product)
  
  class Coming(models.Model):
      # some unimportant fields here
  
  
  class ComingProducts(models.Model):
      coming = models.ForeignKey(Coming)
      priced_product = models.ForeignKey(PricedProduct)
      # more unimportant fields
  </code></pre>
  
  <p>and the following admin.py:</p>
  
  <pre><code>class ComingProductsInline(ForeignKeyCacheMixin, admin.TabularInline):
      model = ComingProducts
  
  
  class ComingAdmin(admin.ModelAdmin):
      inlines = [ComingProductsInline]
  </code></pre>
  
  <p>Of course, i have a problem with multiply queries to database: i have a query for each item in list and a query for each line. So, having 100 items i get 100 ^ 2 queries.
  I've solved the problem with queries for each line with <a href="https://stackoverflow.com/questions/8176200/caching-queryset-choices-for-modelchoicefield-or-modelmultiplechoicefield-in-a-d">Caching queryset choices for ModelChoiceField or ModelMultipleChoiceField in a Django form</a>
  But i still having problem with <strong>str</strong> method. I've tried the following:</p>
  
  <p>1) adding prefetch_related to ComingAdmin:</p>
  
  <pre><code>def get_queryset(self, request):
      return super(ComingAdmin, self).get_queryset(request). \
      prefetch_related('products__product')
  </code></pre>
  
  <p>2) adding select_related to ComingProductInline:</p>
  
  <pre><code>def get_queryset(self, request):
      return super(ComingProductsInline, self).get_queryset(request). \
      select_related('priced_product__product')
  </code></pre>
  
  <p>3) Defining custom form for inline and adding select_related to field queryset:</p>
  
  <pre><code> class ComingProductsInline(ForeignKeyCacheMixin, admin.TabularInline):
       model = ComingProducts
       form = ComingProductsAdminForm
  
   class ComingProductsAdminForm(ModelForm):
       def __init__(self, *args, **kwargs):
                super(ComingProductsAdminForm, self).__init__(args, kwargs)
                self.fields['priced_product'].queryset = PricedProduct.objects.all(). \
                select_related('product')
  
       class Meta:
           model = ComingProducts
           fields = '__all__'
  </code></pre>
  
  <p>4) Defining a custom formset:</p>
  
  <pre><code> class ComingProductsInline(ForeignKeyCacheMixin, admin.TabularInline):
       model = ComingProducts
       formset = MyInlineFormset
  
   class MyInlineFormset(BaseInlineFormSet):
       def __init__(self, data=None, files=None, instance=None,
               save_as_new=False, prefix=None, queryset=None, **kwargs):
          super(MyInlineFormset, self).__init__(data, files, instance,
                                            save_as_new, prefix, queryset, **kwargs)
          self.queryset = ComingProducts.objects.all(). \
          prefetch_related('priced_product__product')
  </code></pre>
  
  <p>5) Different combinations for previous 4 methods</p>
  
  <p>And nothing helps: each call of str for PricedProduct makes Django to perform a query for Product table. All of these methods were mentioned on stackoverflow, but they treated ModelAdmin, and do not help with Inline. What do i miss?</p>