Python django_filters.rest_framework.Filter() Examples
The following are 4
code examples of django_filters.rest_framework.Filter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django_filters.rest_framework
, or try the search function
.
Example #1
Source File: filters.py From resolwe with Apache License 2.0 | 5 votes |
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 )
Example #2
Source File: filters.py From resolwe with Apache License 2.0 | 5 votes |
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")))
Example #3
Source File: filters.py From resolwe with Apache License 2.0 | 5 votes |
def filter_contributor_name(self, queryset, name, value): """Filter queryset by owner's name.""" return queryset.filter(contributor__in=self._get_user_subquery(value))
Example #4
Source File: filters.py From timed-backend with GNU Affero General Public License v3.0 | 5 votes |
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