django object get/set field

前端 未结 4 642
孤城傲影
孤城傲影 2020-12-08 00:52

Can I get the value of an object field some other way than obj.field? Does something like obj.get(\'field\') exist? Same thing for setting the valu

4条回答
  •  臣服心动
    2020-12-08 01:37

    why do you want this?

    You could use

    obj.__dict__['field']
    

    i guess... though it's not a method call

    changed=[field for (field,value) in newObj.__dict__ if oldObj.__dict__[field] != value]
    

    will give you a list of all the fields that where changed.

    (though I'm not 100% sure)

提交回复
热议问题