无法通过(....)实例访问Manager [英] Manager isn't accessible via (....) instances

查看:66
本文介绍了无法通过(....)实例访问Manager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,分别是Stuff和Boss.基于用户的slug(user_type),我定义将要使用的表.

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()

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

然后,我需要从表中获取项目的最后一个ID.

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

但是,当我尝试获取Staff表的最后一个ID时,出现了无法通过Staff实例访问Manager的信息".

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

如何绕过此问题?

推荐答案

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

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

这篇关于无法通过(....)实例访问Manager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆