Skip to content

Commit 4126826

Browse files
author
Ryan P Kilby
committed
Add callable queryset & migration docs
1 parent caa9bfe commit 4126826

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ Example filter calls:
140140
/api/companies?department__name=Accounting
141141
/api/companies?department__manager__name__startswith=Bob
142142
143+
``queryset`` callables
144+
""""""""""""""""""""""
145+
146+
Since ``RelatedFilter`` is a subclass of ``ModelChoiceFilter``, the ``queryset`` argument supports callable behavior.
147+
In the following example, the set of departments is restricted to those in the user's company.
148+
149+
.. code-block:: python
150+
151+
def departments(request):
152+
company = request.user.company
153+
return company.department_set.all()
154+
155+
class EmployeeFilter(filters.FilterSet):
156+
department = filters.RelatedFilter(filterset=DepartmentFilter, queryset=departments)
157+
...
158+
159+
Recursive relationships
160+
"""""""""""""""""""""""
161+
143162
Recursive relations are also supported. It may be necessary to specify the full module path.
144163
145164
.. code-block:: python
@@ -380,6 +399,22 @@ The recommended solutions are to either:
380399
?publish_date__range=2016-01-01,2016-02-01
381400
382401
402+
Migrating to 1.0
403+
----------------
404+
405+
``RelatedFilter.queryset`` now required
406+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
407+
408+
The related filterset's model is no longer used to provide the default value for ``RelatedFilter.queryset``. This
409+
change reduces the chance of unintentionally exposing data in the rendered filter forms. You must now explicitly
410+
provide the ``queryset`` argument, or override the ``get_queryset()`` method (see `queryset callables`_).
411+
412+
413+
``get_filters()`` renamed to ``expand_filters()``
414+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
415+
416+
django-filter has add a ``get_filters()`` classmethod to it's API, so this method has been renamed.
417+
383418
License
384419
-------
385420
Copyright (c) 2013-2015 Philip Neustrom <philipn@gmail.com>,

0 commit comments

Comments
 (0)