+1 as well, I like the idea
with the returning of the boolean - wouldn't it be possible to create
a simple fla/function on a model that would tell you that so that the
function will only have one return parameter?
something like
obj = Person.objects.get_or_create(first_name='John', last_name='Lennon',
defaults={'birthday': date(1940, 10, 9)})
if obj.just_created():
.....
I see this as much more useful, because in situations I imagine I will
want to use this construct, I usually don't care whether its created
or not, so getting a tuple would only complicate (slightly, but still)
things for me.
just to be clear - +1 even with the tuple thing ;)
great idea
On 6/6/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
>
> Adrian Holovaty wrote:
>
> >Time and time again I have the following Django code:
> >
> > try:
> > obj = Person.objects.get(first_name='John', last_name='Lennon')
> > except Person.DoesNotExist:
> > obj = Person(first_name='John', last_name='Lennon',
> >birthday=date(1940, 10, 9))
> > obj.save()
> >
> >
> "Me to!" :-)
>
> So +1 on the proposal.
>
> >* I needed to get both the new object *and* a boolean specifying
> >whether a new object was created, so get_or_create() returns a tuple
> >of (new_object_created, object).
> >
> My first reaction is that it should be reversed: the "primary" returned
> value is an object itself and a flag is often not important so it feels
> like "secondary" value.
>
> >
>
--
Honza Král
E-Mail: [EMAIL PROTECTED]
ICQ#: 107471613
Phone: +420 606 678585
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---