【发布时间】:2012-05-10 16:10:45
【问题描述】:
我已经尝试了很多,但无法弄清楚为什么会这样,
class FortressUserAdmin(admin.ModelAdmin):
list_display(. . . , get_my_schema)
def get_my_schema(self, obj):
sql_query = "select prop_val from customer_property where customer_id = %d and property_value like '%%%%SCHEMA%%%%'" % obj.customer_id.customer_id
property_value = connection.cursor().execute(sql_query).fetch_one()
print sql_query
return 1
# return "aditya"
get_my_schema.short_description = 'Schema Instance'
- 为什么列值总是
(None) - 为什么
print 1或print 'aditya'不会向控制台打印任何内容
专栏管理网站的屏幕截图:
【问题讨论】:
-
请注意,正如我从数据库中看到的那样,并非所有的值/字符串都是空的。
-
我的错!!!它应该是 fetchone() 并且可以工作:-/...
-
您应该添加您的评论作为答案并接受它以关闭问题。
标签: django django-admin python-2.7