当前位置: 首页>>代码示例>>Python>>正文


Python TreeManager.from_queryset方法代码示例

本文整理汇总了Python中mptt.managers.TreeManager.from_queryset方法的典型用法代码示例。如果您正苦于以下问题:Python TreeManager.from_queryset方法的具体用法?Python TreeManager.from_queryset怎么用?Python TreeManager.from_queryset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mptt.managers.TreeManager的用法示例。


在下文中一共展示了TreeManager.from_queryset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MenuUnCacheQuerySet

# 需要导入模块: from mptt.managers import TreeManager [as 别名]
# 或者: from mptt.managers.TreeManager import from_queryset [as 别名]
    for menu in MenuItem.objects.all():
        cache.delete('menu-%s' % menu.slug)
        cache.delete('menu-tree-%s' % menu.slug)


class MenuUnCacheQuerySet(TreeQuerySet):
    def delete(self, *args, **kwargs):
        delete_cache()
        super(MenuUnCacheQuerySet, self).delete(*args, **kwargs)

    def update(self, *args, **kwargs):
        delete_cache()
        super(MenuUnCacheQuerySet, self).update(*args, **kwargs)


MenuItemManager = TreeManager.from_queryset(MenuUnCacheQuerySet)


class MenuItem(MPTTModel):

    parent = TreeForeignKey('self', null=True, blank=True, related_name='children',
                            on_delete=models.CASCADE)
    label = models.CharField(
        _('label'),
        max_length=255,
        help_text="The display name on the web site.",
    )
    slug = models.SlugField(
        _('slug'),
        unique=True,
        max_length=255,
开发者ID:caktus,项目名称:django-treenav,代码行数:33,代码来源:models.py

示例2: user_access_filter

# 需要导入模块: from mptt.managers import TreeManager [as 别名]
# 或者: from mptt.managers.TreeManager import from_queryset [as 别名]
    def user_access_filter(self, user):
        # personal folders
        filter = Q(owned_by=user)

        # folders owned by orgs in which the user a member
        orgs = user.get_orgs()
        if orgs:
            filter |= Q(organization__in=orgs)

        return filter

    def accessible_to(self, user):
        return self.filter(self.user_access_filter(user))


FolderManager = TreeManager.from_queryset(FolderQuerySet)


class Folder(MPTTModel):
    name = models.CharField(max_length=255, null=False, blank=False)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
    creation_timestamp = models.DateTimeField(auto_now_add=True)
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='folders_created',)

    # this may be null if this is the shared folder for a org
    owned_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name='folders',)

    # this will be set if this is inside a shared folder
    organization = models.ForeignKey(Organization, null=True, blank=True, related_name='folders')

    # true if this is the apex shared folder (not subfolder) for a org
开发者ID:,项目名称:,代码行数:33,代码来源:


注:本文中的mptt.managers.TreeManager.from_queryset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。