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 > 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: 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. > 3. related_name for ForeignKey and ManyToManyField > related_name defaults to OBJECT_set if not specified +1 Luke -- "I imagine bugs and girls have a dim suspicion that nature played a cruel trick on them, but they lack the intelligence to really comprehend the magnitude of it." (Calvin and Hobbes) Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/