On Thu, Mar 26, 2009 at 12:53 PM, David Lindquist <david.lindqu...@gmail.com > wrote:
> > I am noticing some odd SQL being generated for certain queries. For > example, if I type the following in the shell: > > >>> TroubleCode.objects.all()[:5] > > and then I look at the db queries: > > >>> from django.db import connection > >>> connection.queries > > I get the desired query, plus 5 extra queries corresponding to the > number in the LIMIT clause: > Your __unicode__ method for TroubleCode: def __unicode__(self): return '%s: %s' % (self.number, self.make) accesses self.make, which is a ForeignKey. Its unicode method accesses one of its fields, but since you did not use select_related() in retrieving your TroubleCode queryset the related model's fields were not pre-loaded during the initial query. So for printing out the repr of the queryset, an individual query must be made for each TroubleCode, to access the related object's 'make' CharField. Karen > > http://dpaste.com/19538/ > > Here are the models I am using: > > http://dpaste.com/19541/ > > Any idea why this is happening? I don't notice this behavior in other > models. > > I am using Django 1.0.2 > > > > --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---