Remove deprecated order_by docs

This commit is contained in:
Ryan P Kilby 2016-11-08 11:41:17 -05:00
parent aba7021742
commit 9fb50e5b60
1 changed files with 0 additions and 61 deletions

View File

@ -10,7 +10,6 @@ Meta options
- :ref:`model <model>`
- :ref:`fields <fields>`
- :ref:`exclude <exclude>`
- :ref:`order_by <order-by>`
- :ref:`form <form>`
- :ref:`together <together>`
- filter_overrides
@ -92,40 +91,6 @@ declared directly on the ``FilterSet``.
exclude = ['password']
.. _order-by:
Ordering using ``order_by``
~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can allow the user to control ordering by providing the
``order_by`` argument in the Filter's Meta class. ``order_by`` can be either a
``list`` or ``tuple`` of field names, in which case those are the options, or
it can be a ``bool`` which, if True, indicates that all fields that
the user can filter on can also be sorted on. An example of ordering using a list::
import django_filters
class ProductFilter(django_filters.FilterSet):
price = django_filters.NumberFilter(lookup_expr='lt')
class Meta:
model = Product
fields = ['price', 'release_date']
order_by = ['price']
If you want to control the display of items in ``order_by``, you can set it to
a list or tuple of 2-tuples in the format ``(field_name, display_name)``.
This lets you override the displayed names for your ordering fields::
order_by = (
('name', 'Company Name'),
('average_rating', 'Stars'),
)
Note that the default query parameter name used for ordering is ``o``. You
can override this by setting an ``order_by_field`` attribute on the
``FilterSet``'s Meta class to the string value you would like to use.
.. _form:
Custom Forms using ``form``
@ -202,29 +167,3 @@ filters for a model field, you can override ``filter_for_lookup()``. Ex::
# use default behavior otherwise
return super(ProductFilter, cls).filter_for_lookup(f, lookup_type)
``get_ordering_field()``
~~~~~~~~~~~~~~~~~~~~~~~~
If you want to use a custom widget, or in any other way override the ordering
field you can override the ``get_ordering_field()`` method on a ``FilterSet``.
This method just needs to return a Form Field.
Ordering on multiple fields, or other complex orderings can be achieved by
overriding the ``FilterSet.get_order_by()`` method. This is passed the selected
``order_by`` value, and is expected to return an iterable of values to pass to
``QuerySet.order_by``. For example, to sort a ``User`` table by last name, then
first name::
class UserFilter(django_filters.FilterSet):
class Meta:
order_by = (
('username', 'Username'),
('last_name', 'Last Name')
)
def get_order_by(self, order_value):
if order_value == 'last_name':
return ['last_name', 'first_name']
return super(UserFilter, self).get_order_by(order_value)