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

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -