#25086: Allow mass-update of fields in unpersisted model instances
-------------------------------------+-------------------------------------
     Reporter:  yoongkang            |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by yoongkang):

 Yep. I have a pull request on GitHub, but basically the method should take
 a dictionary where the keys are the names of the field, and the values are
 the updated field values.

 This code snippet should do the trick:

 {{{
 def assign_attributes(self, values_dict):
     keys = values_dict.keys()
     fields = [f.name for f in self._meta.get_fields()]
     for k in keys:
         if k in fields:
             setattr(self, k, values_dict[k])

 }}}

 There is a similar method in Rails which I'm used to using:
 http://api.rubyonrails.org/classes/ActiveRecord/AttributeAssignment.html

--
Ticket URL: <https://code.djangoproject.com/ticket/25086#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.5f984256d9a496a72df2535f3d9e7e10%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to