[Django]-Django: getattr function (get field name)

7👍

modelInstance=ConfigConsModel()

This initializes modelInstance as new (empty) instance of ConfigConsModel class

newAttrName1=getattr(modelInstance, "configCons")

This line is equivalent to

newAttrName1=modelInstance.configCons

It does not get attribute’s name, it gets it’s value. Which of course is empty.

👤vartec

Leave a comment