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()
>
> This pattern gets quite unwieldy as the number of fields in a model goes up.
>
> So I'm proposing a Manager.get_or_create() method, which I believe was
> Jacob's idea a few months ago. You would pass it keyword arguments to
> use in get(), and you'd pass an optional "defaults" keyword argument
> which would specify the kwargs to use in creating a new object if the
> object matching the get parameters doesn't already exist.
return (True, obj)
I understand why you might need this, but at the HTTP level, when the
example for this goes into the docs, can it be wrapped inside a
request.POST? That will stop someone somewhere from using get_or_create
via a GET view.
cheers
Bill
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---