如何在你能创建的容器上分开访问?

2024-04-23 17:48:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个关于烧瓶管理方法特性的条件。你知道吗

但是混淆了如何在用户角色之间提供一个条件,比如在可以创建功能中。你知道吗

以下是我的modelview的片段:

class UserModelView(sqla.ModelView):

    if current_user.has_role == 'superuser':
        can_create = True
    elif current_user.has_role == 'client':
        can_create = False

但我很少出错,我也尝试过不同的方法,比如:

class UserModelView(sqla.ModelView):
    def is_visible(self):
        if current_user.has_role == 'superuser':
            can_create = True
        elif current_user.has_role == 'client':
            can_create = False

我也在BaseModelView类上尝试了其他方法,但仍然不能像我所希望的那样工作。你知道吗

所以。。有没有可能在那个功能中给出条件的。。?你知道吗


Tags: 方法功能ifcreatecurrent条件canclass
1条回答
网友
1楼 · 发布于 2024-04-23 17:48:26

我遵循这个solution是基于@gitter的建议,它在中工作,可以创建特性,谢谢@gitter。你知道吗

但不幸的是,它不能在另一个条件下工作,如form\u excluded\u columns

是的。你知道吗

编辑: 对于方法(即:可以创建BaseModelView类I开始

但是对于另一种方法,如form\u excluded\u columns,我使用this way,而this way也可以工作。你知道吗

相关问题 更多 >