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

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -