thank you again Bill :0 makes perfect sense now.

On Thursday, December 27, 2012 12:35:16 AM UTC, ke1g wrote:
>
>
>
> On Wed, Dec 26, 2012 at 3:50 PM, Glyn Jackson <cfsp...@gmail.com<javascript:>
> > wrote:
>
>> ke1g, thank you for such a well written reply, clearly explained, I learn 
>> a lot. again thanks.
>>
>> The only bit I'm struggling to understand is the last part you state
>>
>> "The use of "thisPoints" in calculating "totalPoints" doesn't change 
>> "thisPoints".  You can still enumerate it in the template, and get the same 
>> result."
>>
>
> Manager and queryset methods like "filter" return a new queryset, which is 
> a python class instance holding all the things that you have said about 
> your query, but it hasn't touched the database as yet.  When you use 
> something like "filter" on an existing queryset, the original information 
> is still in the original queryset, it has been copied as necessary in the 
> construction of the new queryset.
>
> A queryset is "evaluated" only when you try to use what's in the queryset, 
> such as "list(qs)" or "for r in qs" (including the template language's 
> "for"), or when you print it in the manage.py shell, as examples.  And only 
> when it is evaluated, does it wind up composing SQL, send it to the 
> database, parse the result into model instances (and cacheing these as part 
> of doing requests with large numbers of results in chunks, among other 
> things).  You really get quite a number of splendid optimizations when you 
> use the ORM.
>
> So at the time I showed applying "aggregate" to the "thisPoints" queryset, 
> "thisPoints" hadn't touched the database.  At that time, it is specifically 
> NOT a list of instances.  It is still a queryset class instance.  And the 
> "aggregate" method uses what's in it, but doesn't change it.  Later, in 
> your template, where you presumably apply a "for" template tag to it, is 
> when it uses what it knows to get stuff for you from the database.
>
> Bill
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Eo93nblTwTkJ.
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.

Reply via email to