DavidA wrote: > I have some models that look like this > > class Analyst(models.Model): > name = models.CharField(maxlength=20, unique=True) > > class Strategy(models.Model): > name = models.CharField(maxlength=20) > description = models.CharField(maxlength=80) > > class Inst(models.Model): > strategy = models.ForeignKey('Strategy', blank=True, null=True) > analyst1 = models.ForeignKey('Analyst', related_name='analyst1', > blank=True, null=True) > analyst2 = models.ForeignKey('Analyst', related_name='analyst2', > blank=True, null=True) > analyst3 = models.ForeignKey('Analyst', related_name='analyst3', > blank=True, null=True) > > class Position(models.Model): > date = models.DateField(db_index=True) > inst = models.ForeignKey(Inst) > quantity = fields.NumberField() > > I'm doing a query that starts with Position.objects.select_related() > and I can see that its joining in the Inst tables but not the Analyst > (which would need to be joined through Inst). > > Is that by design? Just curious as I'm getting extra selects to lookup > the Analyst. > > But what's more curious is that when I get back 20 positions and render > them in the template, this results in one select to Strategy, but 20 > selects to Analyst: > > {% for pos in object_list %} > <td>{{ pos.inst.strategy.name }}</td> > <td>{{ pos.inst.analyst1.name }}</td> > {% endfor %} > > Shouldn't they both be cached? Is there something weird going on > because I have three FK's to Analyst where it fails to cache? > > Thanks, > -Dave
OK. I'm an idiot. I can't even read my own debug output. Neither lookup table (Analyst or Strategy) is being cached - both expressions result in 20 separate select queries but its going back to the DB for the same ID many times. That still seems like a problem to me. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---