+1 on both. I was needing this just the other day. Michael
On 7/13/07, Brian Harring <[EMAIL PROTECTED]> wrote: > > On 7/13/07, Adrian Holovaty <[EMAIL PROTECTED]> wrote: > > On 7/13/07, SmileyChris <[EMAIL PROTECTED]> wrote: > > > Adrian, I think it's useful enough. But why do you need a .exists() if > > > we could just use __nonzero__ (like Ivan suggested)? > > > > I hadn't thought of that! Yes, we should definitely implement a > > QuerySet.__nonzero__() method. However, I'd like there to be an > > explicit method (named either exists() or any() or whatever), because > > it's easier to say this: > > > > To determine whether a QuerySet has at least one record, call its > > exists() method. > > > > ...than this: > > > > To determine whether a QuerySet has at least one record, put it in > > an "if" statement > > tell them to do bool(QuerySetInstance) then; its basically what if is > doing anyways, and any decent python users will recognize the bool as > being redundant. > > > It's convenient to be able to access the result of exists() inline, > > rather than having to use it in a certain context, such as within an > > "if" clause. Sure, if we went with only __nonzero__(), you could call > > __nonzero__() directly, but accessing the Python double-underscore > > magic methods is slightly ugly. > > And kills kittens (the protocol methods there usually should be > accessible by the paired builtin ;). > > Either way, -1 on exists, +1 on nonzero. > ~harring > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---