0

我有两张桌子,即 Stuff 和 Boss。根据来自用户的 slug(user_type),我定义将使用哪个表。

def Person_info(request,user_type):
    if user_type=="Staff":
        item=Staff()
    elif user_type=="Boss":
        item=Boss()

.................

然后,我需要从它的表中获取 item 的最后一个 id。

但是,当我尝试获取 Staff 表的最后一个 id 时,我遇到了“无法通过 Staff 实例访问 Manager”。

我怎样才能绕过这个问题?

4

1 回答 1

2

您正在使用实例进行查询,这是不正确的。

更改您的代码如下:

def Person_info(request,user_type):
if user_type=="Staff":
    # Note no () at the end, which makes the item an instance by instantiating it, not a class by assigning it
    item=Staff
elif user_type=="Boss":
    item=Boss
....
于 2012-09-07T04:18:56.003 回答