@@ -24,6 +24,10 @@ Using ``django-rest-framework-filters``, we can easily do stuff like::
2424 /api/article?author__first_name__icontains=john
2525 /api/article?is_published!=true
2626
27+ .. contents ::
28+ **Table of Contents **
29+ :local:
30+ :depth: 2
2731
2832Features
2933--------
@@ -305,8 +309,8 @@ To work around this, you have the following options:
305309 model = Product
306310
307311
308- Can I mix and match `django- filter ` and `django- rest- framework- filters` ?
309- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312+ Can I mix and match `` django- filter `` and `` django- rest- framework- filters` `?
313+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310314
311315Yes you can. `` django- rest- framework- filters`` is simply an extension of `` django- filter `` . Note
312316that `` RelatedFilter`` and other `` django- rest- framework- filters`` features are designed to work
@@ -332,6 +336,49 @@ and ``FilterSet``s from either package are compatible with the other's DRF backe
332336 drf = rest_framework_filters.RelatedFilter(filterset = DRFFilter)
333337
334338
339+ Caveats & Limitations
340+ ~~~~~~~~~~~~~~~~~~~~~
341+
342+ `` MultiWidget`` is incompatible
343+ """ """ """ """ """ """ """ """ """ """ "
344+
345+ djangorestframework- filters is not compatible with form widgets that parse query names that differ from the filter ' s
346+ attribute name. Although this only practically applies to `` MultiWidget`` , it is a general limitation that affects
347+ custom widgets that also have this behavior. Affected filters include `` RangeFilter`` , `` DateTimeFromToRangeFilter`` ,
348+ `` DateFromToRangeFilter`` , `` TimeRangeFilter`` , and `` NumericRangeFilter`` .
349+
350+ To demonstrate the incompatiblity, take the following filterset:
351+
352+ .. code- block:: python
353+
354+ class PostFilter(FilterSet):
355+ publish_date = filters.DateFromToRangeFilter()
356+
357+ The above filter allows users to perform a `` range `` query on the publication date. The filter class internally uses
358+ `` MultiWidget`` to separately parse the upper and lower bound values. The incompatibility lies in that `` MultiWidget``
359+ appends an index to its inner widget names. Instead of parsing `` publish_date`` , it expects `` publish_date_0`` and
360+ `` publish_date_1`` . It is possible to fix this by including the attribute name in the querystring, although this is
361+ not recommended.
362+
363+ .. code- block::
364+
365+ ? publish_date_0=2016 - 01 - 01 & publish_date_1=2016 - 02 - 01 & publish_date=
366+
367+ `` MultiWidget`` is also discouraged since:
368+
369+ * `` core- api`` field introspection fails for similar reasons
370+ * `` _0`` and `` _1`` are less API - friendly than `` _min`` and `` _max``
371+
372+ The recommended solutions are to either:
373+
374+ * Create separate filters for each of the sub- widgets (such as `` publish_date_min`` and `` publish_date_max`` ).
375+ * Use a CSV - based filter such as those derived from `` BaseCSVFilter`` / `` BaseInFilter`` / `` BaseRangeFilter`` . eg,
376+
377+ .. code- block::
378+
379+ ? publish_date__range=2016 - 01 - 01 ,2016 - 02 - 01
380+
381+
335382License
336383------ -
337384Copyright (c) 2013 - 2015 Philip Neustrom < philipn@ gmail.com> ,
0 commit comments