Manager isn't accessible via (…) instances

夙愿已清 提交于 2020-01-06 20:03:18

问题


I have two tables namely Stuff and Boss. Based on the slug(user_type) from the user, I define which table is going to be used.

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

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

Then, I need to get the last id for item from its table.

But, I am having "Manager isn't accessible via Staff instances" When I try to get the last id of Staff table.

How can I bypass this problem ?


回答1:


You are querying using the instance, which is incorrect.

Change your code as below:

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
....


来源:https://stackoverflow.com/questions/12311588/manager-isnt-accessible-via-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!