On Dec 2, 2007 8:31 AM, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > 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.
Frankly, I have found the slicing syntax hard to understand and error-prone myself. I think one of the reasons it seems magic is that it's one of the *rare* cases in which we use a Python "magic-syntax-ism" (like operator overloading, for instance) in the framework, plus the fact that, what, *every* other piece of QuerySet functionality uses a method. It seems bolted on. I'd be +1 on adding a distinct limit() method, and keeping the legacy list method for masochists who actually enjoy coding in that way. Adrian -- Adrian Holovaty holovaty.com | djangoproject.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---