Django使用字符串作为查询对象属性

时间:2015-05-05 11:02:16

标签: django

我想使用string属性

访问查询
>>> colObj = College.objects.get(id=1)
>>> name = "collegeName"

现在我想使用对象属性作为string的大学名称。

例外输出:

>>> colName = colObj.name
>>> colname
>>> 'abc'

1 个答案:

答案 0 :(得分:2)

使用getattr()功能:

$('#table1 tr:nth-last-child(2)').find('select').append("<option>rose</option>");