本文整理汇总了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,
示例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