在 2009-7-20,0:33,Alex Gaynor <[email protected]> 写到:

>
> On Sun, Jul 19, 2009 at 10:48 AM, aXqd<[email protected]> wrote:
>>
>> Hi, all:
>>
>> Recently, I linked two models ( FOO & BAR ) with a foreign key.
>> Then I retrieved the whole records back with the following codes:
>>
>> 1 for item in FOO.objects.all():
>> 2   print item.bar.id
>>
>> In my opinion, the whole thing should be lazy enough.
>> So if Line 1 got all the BAR id back, *WHY* did Line 2 still  
>> trigger a
>> SQL query to retrieve the whole BAR object while all I want here was
>> just that ID, which, I think, was already known by django at this
>> time?
>> Am I missing something here?
>>
>> Thanks.
>>
>> --
>> Regards.
>> -Tian
>>
>>>
>>
>
> Try doing item.bar_id.  Doing item.bar causes Django to load up the
> bar object, but if all you want is the id you can use "bar_id".
>
> Alex
>
> -- 
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
>
> >

It works. Thanks very much :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to