akvo.rest.filters module

class akvo.rest.filters.RSRGenericFilterBackend[source]

Bases: BaseFilterBackend

filter_queryset(request, queryset, view)[source]

Return a queryset possibly filtered by query param values. The filter looks for the query param keys filter and exclude For each of these query param the value is evaluated using ast.literal_eval() and used as kwargs in queryset.filter and queryset.exclude respectively.

Example URLs:

https://rsr.akvo.org/rest/v1/project/?filter={‘title__icontains’:’water’,’currency’:’EUR’} https://rsr.akvo.org/rest/v1/project/?filter={‘title__icontains’:’water’}&exclude={‘currency’:’EUR’}

It’s also possible to specify models to be included in select_related() and prefetch_related() calls on the queryset, but specifying these in lists of strings as the values for the query sting params select_relates and prefetch_related.

Example:

https://rsr.akvo.org/rest/v1/project/?filter={‘partners__in’:[42,43]}&prefetch_related=[‘partners’]

Finally limited support for filtering on multiple arguments using logical OR between those expressions is available. To use this supply two or more query string keywords on the form q_filter1, q_filter2… where the value is a dict that can be used as a kwarg in a Q object. All those Q objects created are used in a queryset.filter() call concatenated using the | operator.