Adrian Holovaty wrote: > This comes back to the Person.objects.all() thing that I'd mentioned > earlier. With all(), there's no strange special-case behavior. > Person.objects.all() would return a cache-filled object, and there > wouldn't be a need for a QuerySet to know whether it could accept > caching or not. > > def some_view(request): > person_list = Person.objects.all() > return render_to_response('foo/person_list', {'person_list': > person_list}) > > This would further simplify things by making a Manager's methods > *return* QuerySets instead of having a Manager *be* a QuerySet. The > downside is it's slightly more typing to do Person.objects.all() than > Person.objects -- but that's the only downside I see. Thoughts?
Glad you brought this up, I was intending to post along similar lines. Consider this way of creating custom managers: goodArticles = objects.filter(score_gt=50) Presumably this needs the same behaviour as a Manager i.e. doesn't cache. So the the filter method needs to return a non-caching QuerySet. To get a caching version, you would have to do .all(), so you would have to do this everytime you actually wanted to get data: Article.objects.all().filter(blah..) Would that be acceptable? Alternatively, we could say that the above method of creating custom managers is wrong, and you should use subclassing instead. Also, with this syntax, you could still have Managers *being* QuerySets (and it would probably be easier to implement it this way). All that happens is that they are non-caching, and all the methods on them (or just .all(), depending on the answer to the above) return new sets with caching turned on. Finally, the other idea of using list() turns out really bad. From what I can tell, list(iterable) calls __len__ on that iterable if it exists (after having fetched the data, for some unknown reason), so with the current behaviour of __len__ on QuerySets, list(Article.objects) fetches the data twice if caching is disabled (as currently). You actually have to do list(iter(Article.objects)). Nasty! Luke