django: getattr function (get field name) -
i can't make function getattr work. here code:
print configconsmodel()._meta.get_all_field_names() #['codesectrepmodel', 'configcons', 'id'] modelinstance=configconsmodel() newattrname1=getattr(modelinstance, "configcons") print newattrname1 #empty -> pb what's wrong?
modelinstance=configconsmodel() this initializes modelinstance new (empty) instance of configconsmodel class
newattrname1=getattr(modelinstance, "configcons") this line equivalent to
newattrname1=modelinstance.configcons it not attribute's name, gets it's value. of course empty.
Comments
Post a Comment