On Thu, 2006-07-20 at 10:41 -0700, markguy wrote: > Derek, > > I appreciate the followup. That works, but I have to say, I don't > understand *why* it works! It's as if Django automagically follows > ForeignKeys, without having to call select_related().
It is exactly like this. The select_related() is purely an optimisation. If you never call it, you won't notice any difference. > > It's also highly confusing that you call > 'labelingredient.ingredient.name' and not > 'labelingredient.ingredient_id.name', but that might be because I'm > expecting this to work like a perl hash. Yet another reason to stop thinking in Perl. :-) Well, lableingredient.ingredient is the attribute that contains the foreign key object (accessing that returns the object the is referred to). So you access the foreign key object and then access attributes on that. As you conclude later in the thread, stop worrying about how it is working if that is twisting your mind around, just think of it as normal object-based attribute access. "Somehow" Django will load the right data for you and you can just wander around the model in a normal Python fashion. Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---