> I like the thoughts behind the changes, it seems to make it more
> consistent and compact, however what confused me was:
> 
> p1.article_set.order_by('headline')
> 
> One could read this as setting order by for p1.article.  It is
> unclear, to my reading, what this would accomplish.  There's no
> correlation to the fact that you are retrieving data with
> p1.article_set, which is what get_article_list did convey.

I think that we can reasonably expect people to know that _ is not the
attribute lookup operator, and that . is.

article_set is a collection, you are calling the order_by method on that
collection.

The thing is it isn't really a list. Its a set, because it might not
have a meaningful order, and it can't have repeated entries (at least id
must differ).

Is your confusion between set the verb and set the noun ? I don't really
know how to fix that without refactoring the English language.  I don't
know what else could be done here - pluralisation is a no no, etc etc.
If you can come up with a better automatic name than <whatever>_set, let
me know.

Also, attribute access is retrieving data in all cases. The only thing
varying is where the data is coming from.

> This is especially interesting given:
> 
> reporter.article_set
> reporter.article_set.filter(headline__startswith='This').order_by('headline')
> reporter.article_set.add(headline="John's second story",
> pub_date=datetime(2005, 7, 29))
> 
> Where you added explicit functions for filter() and add(), but getting
> the complete list is made implicit in article_set.  Wouldn't this kind
> of go against the philosophy of Django?

Getting the list is implicit for filter() as well. Filter is just for
adding extra lookup parameters. *Nothing* is loaded from the database
until a collection method like __iter__() or __getitem__()
is called, eg by doing

for article in reporter.article_set:
    # whatever

or

articles = reporter.article_set.order_by('headline')
a = articles[10]

Neither of the first two statements above will access anything from the
db until you ask them to. Really, it all works the same way.

add() is different, as it doesn't need to fetch any data.

Reply via email to