Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Shawn Milochik
If the question is answered to your satisfaction, why don't we drop the thread now and avoid the personal stuff? There is nothing to be gained by arguing with a respected core Django developer, and nothing the rest of us will learn from it. Thanks, Shawn -- You received this message

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> The only condescension I've seen in this thread is from you. And, to > be fair, if I wanted to be condescending I'd have simply pointed you > at Tony Hoare's explanation of null values That's why I said NullObject, in the first post. -- You received this message because you are subscribed to

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread James Bennett
On Thu, Mar 4, 2010 at 1:43 PM, Phlip wrote: > And again the condescension. As a programmer, I should be able to > easily chose between statements that throw and ones that efficiently > deal with branching conditions. A record-not-found is not a crisis, it > is just a

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Shawn Milochik
Just create your own Manager and override the default (named 'objects') in your models. Have 'get' behave any way you like. http://docs.djangoproject.com/en/1.1/topics/db/managers/ Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> Just create your own Manager and override the default (named 'objects') in > your models. Have 'get' behave any way you like. > > http://docs.djangoproject.com/en/1.1/topics/db/managers/ > > Shawn Ding! http://docs.djangoproject.com/en/1.1/topics/db/managers/#adding-extra-manager-methods luv

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> Most likely, yes. And those people, believe it or not, designed > Django's APIs based on their experiences. This is why there are > shortcuts available, like the get_or_create() method (which fetches an > object or, if none matches, creates a valid one, populated with > default values you

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread James Bennett
On Thu, Mar 4, 2010 at 12:59 PM, Phlip wrote: > Doesn't anyone in Django-land have experience with the platforms that > make this problem incredibly easy? Most likely, yes. And those people, believe it or not, designed Django's APIs based on their experiences. This is why

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
> from django.core.exceptions import ObjectDoesNotExist txbut... >sigh< I was hoping to head that off - Python's condescending attitude is in fact the core of the problem. Even if you wrap all your try: except: up in a method, so it's at least DRY, is you must consign that method to use .get().

Re: shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread rebus_
On 4 March 2010 18:02, Phlip wrote: > Djangoids: > > Consider this line: > >   foo = Foo.object.get(name='bar') > > If foo is not found, I want it to contain a NullObject, such as an > empty Foo(). In the parlance, that could be like this: > >   foo =

shortest way to recover from a QuerySet "object not found"

2010-03-04 Thread Phlip
Djangoids: Consider this line: foo = Foo.object.get(name='bar') If foo is not found, I want it to contain a NullObject, such as an empty Foo(). In the parlance, that could be like this: foo = Foo.object.get(name='bar', _default=Foo()) I naturally don't expect (v 1.1.1) of Django to