Re: save() method could return the object

2012-10-12 Thread Alex Gaynor
On Fri, Oct 12, 2012 at 6:40 AM, Chris Wilson wrote: > On Fri, 12 Oct 2012, Marijonas Petrauskas wrote: > > There already exists create method that does exactly what you need:obj = >> SomeModel.objects.create(name=**'foo', age=42) >> > > OK, thanks, that appears to be completely undocumented. >

Re: save() method could return the object

2012-10-12 Thread Chris Wilson
On Fri, 12 Oct 2012, Marijonas Petrauskas wrote: There already exists create method that does exactly what you need:obj = SomeModel.objects.create(name='foo', age=42) OK, thanks, that appears to be completely undocumented. Cheers, Chris. -- Aptivate | http://www.aptivate.org | Phone: +44 122

Re: save() method could return the object

2012-10-12 Thread Alex Gaynor
On Fri, Oct 12, 2012 at 6:36 AM, Yo-Yo Ma wrote: > +1 > > A lot of people are overriding ``save`` and not returning anything, but > this isn't going to hurt them (ideally, they should already be returning > the result of ``super(``, but nobody does). > > > On Friday, October 12, 2012 9:25:46 AM U

Re: save() method could return the object

2012-10-12 Thread Yo-Yo Ma
+1 A lot of people are overriding ``save`` and not returning anything, but this isn't going to hurt them (ideally, they should already be returning the result of ``super(``, but nobody does). On Friday, October 12, 2012 9:25:46 AM UTC-4, Chris Wilson wrote: > > Hi all, > > If the save() method

Re: save() method could return the object

2012-10-12 Thread Marijonas Petrauskas
There already exists create method that does exactly what you need: obj = SomeModel.objects.create(name='foo', age=42) On Fri, Oct 12, 2012 at 2:33 PM, David Winterbottom < david.winterbot...@tangentlabs.co.uk> wrote: > While such a change is initially appealing, it violates the command-query > s

Re: save() method could return the object

2012-10-12 Thread David Winterbottom
While such a change is initially appealing, it violates the command-query separation principle in that a 'command' method such as 'save' should not return anything. http://en.wikipedia.org/wiki/Command-query_separation Hence, it's not a good idea to make this change. It's more important to have c

save() method could return the object

2012-10-12 Thread Chris Wilson
Hi all, If the save() method returned the object itself, then we could chain it like this: old_status = Status(last_contact=None).save() Instead of having to do this: old_status = Status(last_contact=None) old_status.save() It's a trivial one-line change to the Model