On Jun 10, 9:27 am, Paolo Corti <pco...@gmail.com> wrote:
> Hi
> is it possible to update an object with a dictionary?
>
> I tried something like this:
> myobject.save(force_update=True, **my_dict)
>
> getting an error, though:
> TypeError at ...
> save() got an unexpected keyword argument 'myfieldname'
>
> I wouldn't like to iterate the dictionary, neither to delete and
> create the object again using the dictionary, is there a best
> approach?
>
.save() is only for persisting the object to disk, not for modifying
objects. To update any Python object from a dictionary is as easy as:
for k,v in d.items(): setattr(myobject, k, v)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---