On 6/6/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
> So I'm proposing a Manager.get_or_create() method, which I believe was
> Jacob's idea a few months ago.
+1 from my side, with Simon's note in mind.
--
Jeroen Ruigrok van der Werven
--~--~-~--~~~---~--~~
Yo
On 6 Jun 2006, at 06:39, Adrian Holovaty wrote:
> * Currently this assumes the model has no field named "defaults". This
> is a bit of a smell. Better solutions?
It could take two dictionaries instead of using keyword arguments:
obj = Person.objects.get_or_create(
{'first_name':
On 6/6/06, Bill de hÓra <[EMAIL PROTECTED]> wrote:
> 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.
Sure, Bill -- go
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))
>
+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='Len
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))
>ob
It sounds great.any chance of getting a insert_or_replace function as well?to do something similar to mysql 5's INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html(which is the other common pattern I'm seeing in my
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 quit