> > On 8/29/07, Bjorn Ruud <[EMAIL PROTECTED]> wrote: > > > > The pool QuerySet gets re-evaluated when the count() in the loop is > > run. Since one of the fields in the filter gets changed, the amount of > > objects in the QuerySet will be different. If pool.count() is replaced > > with len(pool) this does not happen. Is this intended behaviour? Can a > > QuerySet be made immutable?
> On Aug 29, 3:03 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > This behaviour is by design. > > queryset.count() actually constructs (and executes) a new 'SELECT > COUNT(*) FROM table' query. This means that it will always return the > current number of objects matching the query. In your case, the number > of objects is changing, so count() will return a different value each > time. > > len(queryset) returns the length of the evaluated queryset. When the > queryset is evaluated for the first time, it will act as a cache, so > all calls to len(queryset) will return the same value. > Ah, I misunderstood how the caching mechanism works. I thought that after the initial evaluation the QuerySet was static no matter what operation was performed since only the cache was being used. Instead of working directly with the QuerySet I'll construct a list of the necessary primary keys and work with that. Thank you for answering. Regards, Bjorn Ruud --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

