On Fri, 2007-11-30 at 20:00 -0800, [EMAIL PROTECTED] wrote: > To clarify, code such as the following can be a little confusing: > > p = MyModel.objects.filter(foo__id = self.id).order_by('-timestamp')[: > 1] > if p: > return p[0] > > To a python developer who is unfamiliar with django's magic limiting > syntax, the slice there looks unnecessary. > > Writing objects.filter(...).order_by(...).limit(1) would be clearer > and significantly less error prone.
No it wouldn't. It would be differently error-prone. Using Pythonic syntax is nice and it's pretty rare that adding the slice is really going to affect performance, since it only queries the database if you haven't *already* run the database query (if you slice a queryset that is already cached, it pulls the results out of the cache). I'd be -1 on changing this. Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---