Re: PROPOSAL: Manager.get_or_create()

2006-06-06 Thread Jeroen Ruigrok van der Werven
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

Re: PROPOSAL: Manager.get_or_create()

2006-06-06 Thread Simon Willison
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':

Re: PROPOSAL: Manager.get_or_create()

2006-06-06 Thread Adrian Holovaty
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

Re: PROPOSAL: Manager.get_or_create()

2006-06-06 Thread Bill de hÓra
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)) >

Re: PROPOSAL: Manager.get_or_create()

2006-06-06 Thread Honza Král
+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

Re: PROPOSAL: Manager.get_or_create()

2006-06-06 Thread Ivan Sagalaev
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

Re: PROPOSAL: Manager.get_or_create()

2006-06-05 Thread Ian Holsman
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

PROPOSAL: Manager.get_or_create()

2006-06-05 Thread Adrian Holovaty
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