On 1/3/07, Gary Wilson <[EMAIL PROTECTED]> wrote:

Ok, after getting sidetracked by update() and update_or_create(), back
to the topic of the OP.   Here are some options:

1) Add a get_or_none() method that returns None if object does not
exist.

2) Add a get_or_default() method that accepts a "default" keyword
argument, the value of which gets returned if object does not exist.
If a default is not specified then None gets returned by default.

3) Modify the current get() method to accept a "default" keyword
argument as in option 2), except that instead of returning None if
"default" is not specified, a DoesNotExist exception is raised like
normal.  To return None, you would have to explicitly say
"default=None".

Note that this would also be backwards incompatible in that models with
a field named "default" would have to use "default__exact=..." instead
of "default=..." as with get_or_create().  Looking further, it looks
like functions that use get() might also have to change slightly, i.e.
get_or_create().

Comments/votes/suggestions?


I like 3, but considering the potential complications 2 may make more
sense. Either way, I don't see the value in 1 as in either 2 or 3, the
default can still be set to None.


--
----
Waylan Limberg
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
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