#5741: make queryset get() take a default kwarg
------------------------------------+---------------------------------------
Reporter: dcwatson | Owner: nobody
Status: new | Component: Database wrapper
Version: SVN | Resolution:
Keywords: queryset get default | Stage: Unreviewed
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
------------------------------------+---------------------------------------
Comment (by dcwatson):
The patch adds a "default" kwarg, that returns the value of "default" if
it's supplied, and raises the DoesNotExist exception otherwise, like
before. So you can do either of the following:
{{{
try:
foo = Foo.objects.get( pk=myid )
except Foo.DoesNotExist, ex:
foo = None
}}}
or
{{{
foo = Foo.objects.get( pk=myid, default=None )
}}}
I think making get() use the first argument as a primary key lookup is
unnecessary with the "pk" shortcut. Also, I'd imagine it would add a lot
of ugly special-casing, since get() is really a convenience for filter(),
whose positional args (if provided) are expected to be Q objects.
--
Ticket URL: <http://code.djangoproject.com/ticket/5741#comment:4>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---