Skip to content

Commit

Permalink
Add SuffixedMultiWidget docs [skip-ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan P Kilby committed Apr 11, 2017
1 parent 4b84986 commit cb47d16
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/ref/widgets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ a ``RangeField``:
.. code-block:: python

date_range = DateFromToRangeFilter(widget=RangeWidget(attrs={'placeholder': 'YYYY/MM/DD'}))


``SuffixedMultiWidget``
~~~~~~~~~~~~~~~~~~~~~~~

Extends Django's builtin ``MultiWidget`` to append custom suffixes instead of
indices. For example, take a range widget that accepts minimum and maximum
bounds. By default, the resulting query params would look like the following:

.. code-block:: http

GET /products?price_0=10&price_1=25 HTTP/1.1

By using ``SuffixedMultiWidget`` instead, you can provide human-friendly suffixes.

.. code-block:: python

class RangeWidget(SuffixedMultiWidget):
suffixes = ['min', 'max']

The query names are now a little more ergonomic.

.. code-block:: http

GET /products?price_min=10&price_max=25 HTTP/1.1

0 comments on commit cb47d16

Please sign in to comment.