On 21 Nov 2005, at 19:17, Kevin wrote:

class Article(meta.Model):
    online = meta.BooleanField()

But now my views are littered with:

articles.get_list(online__exact=True)

I'd much prefer to have this online check to be done "behind the
scenes" so I don't forget to test for it in someplace....

Rails has a neat solution to this problem: http://api.rubyonrails.com/ classes/ActiveRecord/Base.html#M000728

Article.with_scope(:find => { :conditions => "blog_id = 1" }) do
Article.find(1) # => SELECT * from articles WHERE blog_id = 1 AND id = 1
end

In the above block, all find operations automatically have a "WHERE blog_id = 1" clause added to them.

I'm not sure if this would be easy or even wise to duplicate in Django, but it's an interesting solution.

Cheers,

Simon

Reply via email to