I posted this to Django users, but didn't get a response. I'd like to help 
to resolve this issue if at all possible.

Previous post:

I have the Django admin configured with a TabularInline, and the inline 
model has a ForeignKey reference to a third model. Every row in the inline 
generates a new query to fetch all of the instances of the third model.

Here's an overview of my code:

# models.py
> from django.db import models
>
> class ExampleParent(models.Model):
>     
>     def __unicode__(self):
>         return u'Example Parent: %s' % self.id
>
> class ExampleInline(models.Model):
>     parent = models.ForeignKey('ExampleParent')
>     child = models.ForeignKey('ExampleChild')
>     
>     def __unicode__(self):
>         return u'Example Inline: %s' % self.id
>     
> class ExampleChild(models.Model):
>     
>     def __unicode__(self):
>         return u'Example Child: %s' % self.id
>

# admin.py
> from django.contrib import admin
>
> from admin_issue.example_problem.models import (ExampleParent, 
> ExampleInline)
>
> class ExampleInlineInline(admin.TabularInline):
>     model = ExampleInline
>
> class ExampleParentAdmin(admin.ModelAdmin):
>     inlines = [
>         ExampleInlineInline
>     ]
>
> admin.site.register(ExampleParent, ExampleParentAdmin) 
>

If you create a bunch of ExampleInlines that reference and ExampleParent, 
then go to that instance in the admin, you get QUERY = u'SELECT 
"example_problem_examplechild"."id" FROM "example_problem_examplechild"' - 
PARAMS = () for every ExampleInline referenced. 

Shouldn't that query be cached by Django? Is that expected behavior? Is 
there a way to force Django to use the cache for subsequent inlines?

I'm also experiencing a similar problem with a ManyToMany field. (But it 
seems to generate even more queries that the ForeignKey)

Any help on this issue would be most appreciated.

Thanks,

John P.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/139e1577-86b2-4d96-9da9-c62d3dba2c75%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to