another thing i jsut ran into:

this causes an IndexError
      Model.objects.filter(something)[0]
you have to add the colon before the 0
      Model.objects.filter(something)[:0]
the limit(0) would not bring this error, it would not let
first-time-users run into this problem

another 2 cents

wolfram



On Dec 4, 2007 9:53 AM, Wolfram Kriesing <[EMAIL PROTECTED]> wrote:
> I remember my beginner times with django, i was searching for limit()
> until I had to remind myself multiple times that you have to use [x:y] for it.
> limit() seemed the reasonable straightforward thing ... and thats what
> i am used to from python
> but this time it was different
>
> Providing limit() would be consistent to the rest of the querying API,
> since all
> query building is done using function calls!
>
> my 2 cents
>
> wolfram
>
>
> On Dec 3, 2007 6:28 AM, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
> >
> > 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
> >
> >
> > > >
> >
>
>
>
> --
> cu
>
> Wolfram
>



-- 
cu

Wolfram

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to