本文整理汇总了Python中core.models.Instance.select_by_user方法的典型用法代码示例。如果您正苦于以下问题:Python Instance.select_by_user方法的具体用法?Python Instance.select_by_user怎么用?Python Instance.select_by_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Instance
的用法示例。
在下文中一共展示了Instance.select_by_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_by_user
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import select_by_user [as 别名]
def select_by_user(user):
if user.is_admin:
qs = ReservedResource.objects.all()
else:
instance_ids = [s.id for s in Instance.select_by_user(user)]
qs = ReservedResource.objects.filter(id__in=instance_ids)
return qs
示例2: select_by_user
# 需要导入模块: from core.models import Instance [as 别名]
# 或者: from core.models.Instance import select_by_user [as 别名]
def select_by_user(user):
if user.is_admin:
qs = Port.objects.all()
else:
instances = Instance.select_by_user(user)
instance_ids = [instance.id for instance in instances]
networks = Network.select_by_user(user)
network_ids = [network.id for network in networks]
qs = Port.objects.filter(Q(instance__in=instance_ids) | Q(network__in=network_ids))
return qs