I was thinking a bit more about the magic we currently have.

Assuming the model in
http://www.djangoproject.com/documentation/models/many_to_one/

So, how would people feel about:

reporter.get_article_list()
reporter.get_article_list(headline__startswith='This',
order_by=['headline'])

reporter.add_article(headline="John's second story",
pub_date=datetime(2005, 7, 29))

changing to:

reporter.articles
reporter.articles.filter(headline__startswith='This').order_by('headline')
reporter.articles.add(headline="John's second story",
pub_date=datetime(2005, 7, 29))


?

And

article.get_reporter()
article.reporter_id

changing to:

article.reporter
article.reporter.id
?

So this would be done by turning fields into descriptors and leaving
them in the class rather than removing them, and also adding descriptors
to related classes during setup.

The 'actual' data could be stored as private attributes of the instance,
or all in a private dictionary.

The object returned by the related class descriptor would be a set-like
object which works lazily. It will only actually do the query once
iter() is called on it. Extra parameters are added by methods on this
object that return the object, eg filter() and order_by(). If there is
an ordering either by default in the model or from order_by(), the
object also gains list like methods.

.add would either add a passed in instance, or create a new instance
using kwargs if nothing else is there.

A similar thing could be done for many-to-many fields.
Also, the existing methods could still work as well, not sure if that
would be a good idea though ( confusion).

Reply via email to