#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 Will Hardy):
Or maybe something like:
{{{
foo = Foo.objects.default(None).get(myid)
}}}
This would be backwards compatible and would also avoid any name-conflict
woes. Of course, I don't like that it's not so readable anymore, but it
might be useful.
Another approach is to have get return None instead of an exception:
{{{
foo = Foo.objects.get(myid) or default_object
}}}
But I doubt that the whole !DoesNotExist exception thing would be thrown
away at this stage. Maybe a settings variable can be used to "turn on"
this functionality, to keep it backways compatible and let the user choose
whether or not they want exceptions or return values. This road is getting
a little messy.
A third option is:
{{{
foo = Foo.objects.get_or_none(myid) or default_object
}}}
...but the method needs a better name, because it's really starting to
lose it's readability, but I like it better than the first one.
--
Ticket URL: <http://code.djangoproject.com/ticket/5741#comment:3>
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
-~----------~----~----~----~------~----~------~--~---