Skip to content

Commit

Permalink
Update filter group docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkilby committed Jan 28, 2020
1 parent d17dbb5 commit a246c73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions django_filters/groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import operator
from abc import abstractmethod

from django.core.exceptions import ValidationError
from django.db.models import Q
Expand Down Expand Up @@ -30,6 +31,7 @@ def __init__(self, filters):
self.parent = None
self.model = None

@abstractmethod
def validate(self, form, **data):
"""Validate the subset of cleaned data provided by the form.
Expand All @@ -42,13 +44,17 @@ def validate(self, form, **data):
"""
raise NotImplementedError

@abstractmethod
def filter(self, qs, **data):
"""Filter the result queryset with the subset of cleaned data.
Args:
qs: The ``QuerySet`` instance to filter.
**data: The subset of a form's ``cleaned_data`` for the filters in
the group.
Returns:
The filtered queryset instance.
"""
raise NotImplementedError

Expand Down
13 changes: 6 additions & 7 deletions docs/ref/groups.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ Group Reference
===============

By default, a ``FilterSet`` validates and then filters its query parameters
independently of each other, ultimately resulting in a sequence of chained
``.filter()`` calls. Due to the nature of filter chaining, it's not trivial
to, for example, make a group of filters mutually exclusive, or to OR them
together into a single filter call.
independently of each other, ultimately resulting in a chain of ``.filter()``
calls. Due to the nature of filter chaining, it's not trivial to, for example,
make a group of filters that are mutually exclusive to each other.

Filter groups solve this limitation by processing subsets of parameters
together, enabling higher level validation and filtering behavior.
Expand All @@ -15,9 +14,9 @@ Validation
==========

A filter group only applies group-level validation. For example, a mutually
exclusive group is only responsible for validating that one of its parameters
is present. It is not responsible for individual value validation, which is
still performed by the underlying filter instances.
exclusive group is responsible for validating that *only* one of its parameters
is present. It is not responsible for validating the individual values, which
is still performed by the underlying filter instances.

Filtering
=========
Expand Down

0 comments on commit a246c73

Please sign in to comment.