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


Python rest_framework.Filter方法代码示例

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


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

示例1: filter_owners

# 需要导入模块: from django_filters import rest_framework [as 别名]
# 或者: from django_filters.rest_framework import Filter [as 别名]
def filter_owners(self, queryset, name, value):
        """Filter queryset by owner's id."""
        try:
            user = user_model.objects.get(pk=value)
        except user_model.DoesNotExist:
            return queryset.none()

        return get_objects_for_user(
            user, self.owner_permission, queryset, with_superuser=False
        ) 
开发者ID:genialis,项目名称:resolwe,代码行数:12,代码来源:filters.py

示例2: filter_owners_name

# 需要导入模块: from django_filters import rest_framework [as 别名]
# 或者: from django_filters.rest_framework import Filter [as 别名]
def filter_owners_name(self, queryset, name, value):
        """Filter queryset by owner's name."""
        result = queryset.model.objects.none()
        user_subquery = self._get_user_subquery(value)
        for user in user_subquery:
            result = result.union(
                get_objects_for_user(
                    user, self.owner_permission, queryset, with_superuser=False
                )
            )

        # Union can no longer be filtered, so we have to create a new queryset
        # for following filters.
        return result.model.objects.filter(pk__in=Subquery(result.values("pk"))) 
开发者ID:genialis,项目名称:resolwe,代码行数:16,代码来源:filters.py

示例3: filter_contributor_name

# 需要导入模块: from django_filters import rest_framework [as 别名]
# 或者: from django_filters.rest_framework import Filter [as 别名]
def filter_contributor_name(self, queryset, name, value):
        """Filter queryset by owner's name."""
        return queryset.filter(contributor__in=self._get_user_subquery(value)) 
开发者ID:genialis,项目名称:resolwe,代码行数:5,代码来源:filters.py

示例4: filter

# 需要导入模块: from django_filters import rest_framework [as 别名]
# 或者: from django_filters.rest_framework import Filter [as 别名]
def filter(self, qs, value):
        """Filter for given most frequently used tasks.

        Most frequently used tasks are only counted within last
        few months as older tasks are not relevant anymore
        for today's usage.

        :param QuerySet qs: The queryset to filter
        :param int   value: number of most frequent items
        :return:            The filtered queryset
        :rtype:             QuerySet
        """
        if value in EMPTY_VALUES:
            return qs

        user = self.parent.request.user
        from_date = date.today() - timedelta(days=60)

        qs = qs.filter(
            reports__user=user,
            reports__date__gt=from_date,
            archived=False,
            project__archived=False,
        )
        qs = qs.annotate(frequency=Count("reports")).order_by("-frequency")
        # limit number of results to given value
        qs = qs[: int(value)]

        return qs 
开发者ID:adfinis-sygroup,项目名称:timed-backend,代码行数:31,代码来源:filters.py


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