本文整理匯總了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