Change: Referencing Model Instance Fields Dynamically

created on Oct. 27, 2012, 10:23 a.m. by Hevok & updated on Oct. 27, 2012, 10:23 a.m. by Hevok

To update an prior undeclared model instance using a fields dictionary settattribute can be used::

for k,v in fields.iteritmes():
   setattr(instance, k, v

In the case of ManyToMany relationship attributes its counterpart gettattribute comes in handy::

getattr(instance, k).add(relatedObject)
attributes.jpg

Tags: django
Categories: Tutorial
Parent: Web Framework

Comment: Created entry.

See entry | Admin

Comment on This Data Unit