On Wed, Mar 5, 2014 at 10:05 PM, Paulo Poiati <paulogpoi...@gmail.com>wrote:
> Hello everyone, > > While developing standard web applications one thing I frequently do is > updating just one field of a model instance and save it after that. The > best way to do that today (if you want to avoid the update in all the > fields) is with the code bellow. > > product.name = 'Name changed again' > product.save(update_fields=['name']) > > > I want to propose a shortcut for this kind of operation. I came up with > two solutions. > > *Solution One* > > product.save(update_fields={'name': 'Name changed again'}) > > > *Solution Two (My preferred)* > > product.update_fields(name='Name changed again') > > > What do you guys think about this? > Sorry - can't say I'm a fan of either. If I had to pick one, I'd pick solution 1; solution 2 strikes me as introducing a second way to save models, which the Zen of Python counsels against. However, this at the "would you rather be shot in the knee or shot in the ankle" level of support. The only problem I see with your original "problem" syntax is that there is the potential to set an attribute and then forget it in the update_fields list; however, the price you pay for this is converting save() from a simple "commit" operation into a "modify and commit" operation. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAJxq84_%2B6e7BkjM1z2FhaEQOUOJAo_47j64H1oP2yc4SfcYauQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.