【问题标题】:Django printing status isn't workingDjango 打印状态不起作用
【发布时间】: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 1print 'aditya' 不会向控制台打印任何内容

专栏管理网站的屏幕截图:

【问题讨论】:

  • 请注意,正如我从数据库中看到的那样,并非所有的值/字符串都是空的。
  • 我的错!!!它应该是 fetchone() 并且可以工作:-/...
  • 您应该添加您的评论作为答案并接受它以关闭问题。

标签: django django-admin python-2.7


【解决方案1】:

使用fetchone() 函数代替上面使用的函数..

【讨论】:

    猜你喜欢
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多