Luke Plant wrote: > On Friday 27 January 2006 22:25, Joseph Kocherhans wrote: > > >>1. Model.objects vs. Model.objects.all() >> (and also instance.sites vs. instance.sites.all()?) > > > +1 on Model.objects and instance.sites +1
>>2. len(q) vs. q.count() > > > Actually, can we get away with not having len(q)? If you try to use an > iterator in a template with {{ for foo in iterator_obj }} you get: This bit me before with a generator - I ended up just doing list(func()), but I think for should be fixed to work with iterators not supporting len. > Exception Type: TypeError > Exception Value: len() of unsized object > > You can kind of fix this, but what about using 'reversed'? That > definitely needs to do len(). (You could possibly special case Query > instances in the template code, by adding a .reversed() method which > inverts the order_by tuple ... but that's obviously evil) > In light of this, my earlier proposal was wrong. Instead it should be: > len(q) - retrieves the list, and does len() on it > bool(q) - retrieves the list, and does bool(len()) on it > q.count() - does a select count(*) > > That actually makes more sense - the special method (count) does > something special, the Python builtins just force the data to be > fetched. I think this makes sense... >>3. related_name for ForeignKey and ManyToManyField >> related_name defaults to OBJECT_set if not specified > +1 +1