本文整理汇总了Python中django_filters.Filter方法的典型用法代码示例。如果您正苦于以下问题:Python django_filters.Filter方法的具体用法?Python django_filters.Filter怎么用?Python django_filters.Filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_filters
的用法示例。
在下文中一共展示了django_filters.Filter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_queryset
# 需要导入模块: import django_filters [as 别名]
# 或者: from django_filters import Filter [as 别名]
def get_queryset(self):
queryset = Image.objects.all()
publisher = self.request.query_params.get('publisher', None)
if publisher:
publisher = publisher.lower().split(',')
q = get_publisher_query(publisher)
queryset = queryset.filter(q)
data_source = self.request.query_params.get('data_source')
# Filter by data source, multiple sources separated by comma
if data_source:
data_source = data_source.lower().split(',')
queryset = queryset.filter(data_source__in=data_source)
created_by = self.request.query_params.get('created_by')
if created_by:
if self.request.user.is_authenticated:
# only displays events by the particular user
queryset = queryset.filter(created_by=self.request.user)
else:
queryset = queryset.none()
return queryset