On Jan 26, 2006, at 2:23 AM, hugo wrote:
One nice thing about chained methods is, you can pass around the query
object and modify it after the fact. Think "curried queries" - you
build a partial query and pass it to a function, which itself can add
more query specifications or ordering or stuff like that, without
needing to know about what the actual query is. This opens up a really
nice way to build generic code: you only need to put those query
specifications into your code that _your_ code needs, any filtering
for
example can be done outside.
Ah, interesting -- I hadn't thought about that situation. So
essentially a Query is a curried lookup until you iterate it, yes?
What happens to a query after it's been iterated? For example, how
does the following behave?
::
people = Reporter.objects.filter(fname="Joe")
for p in people:
print p
people2 = people.order_by('fname')
for p in people:
print p
And I think all/filter is quite nice, too - that way you can see
directly whether a query starts with the full set or wether you
work on
a subset. Sure, this can be done with one single method with
parameters, but I rather like the distinguished method names - it's
more readable to me.
Fair enough -- my tastes run the other way towards a single method,
but it's really not the big a deal.
Jacob