Develop update (#574)

* README - add syntax highlighting

Easier to read

* Fixes typo in FiterSet docs

Adds the missing letter "t" to DateRangeFiler.
This commit is contained in:
Carlton Gibson 2016-11-28 15:46:51 +01:00 committed by GitHub
parent 75ede3bedd
commit 2ece1c1fff
2 changed files with 14 additions and 10 deletions

View File

@ -19,11 +19,15 @@ Requirements
Installation
------------
Install using pip::
Install using pip:
.. code-block:: sh
pip install django-filter
Or clone the repo and add to your PYTHONPATH::
Or clone the repo and add to your ``PYTHONPATH``:
.. code-block:: sh
git clone git@github.com:carltongibson/django-filter.git
@ -35,7 +39,7 @@ admin's ``list_filter`` interface. It has an API very similar to Django's
``ModelForms``. For example, if you had a Product model you could have a
filterset for it with the code:
.. code:: python
.. code-block:: python
import django_filters
@ -47,16 +51,16 @@ filterset for it with the code:
And then in your view you could do:
.. code:: python
.. code-block:: python
def product_list(request):
filter = ProductFilter(request.GET, queryset=Product.objects.all())
return render(request, 'my_app/template.html', {'filter': filter})
Django-filters additionally supports specifying FilterSet fields using a
dictionary to specify filters with lookup types:
Django-filters additionally supports specifying ``FilterSet`` fields using
a dictionary to specify filters with lookup types:
.. code:: python
.. code-block:: python
import django_filters
@ -67,8 +71,8 @@ dictionary to specify filters with lookup types:
'price': ['exact', 'gte', 'lte'],
}
The filters will be available as 'name', 'name__icontains', 'price',
'price__gte', and 'price__lte' in the above example.
The filters will be available as ``'name'``, ``'name__icontains'``,
``'price'``, ``'price__gte'``, and ``'price__lte'`` in the above example.
Support
-------

View File

@ -193,7 +193,7 @@ filters for a model field, you can override ``filter_for_lookup()``. Ex::
def filter_for_lookup(cls, f, lookup_type):
# override date range lookups
if isinstance(f, models.DateField) and lookup_type == 'range':
return django_filters.DateRangeFiler, {}
return django_filters.DateRangeFilter, {}
# use default behavior otherwise
return super(ProductFilter, cls).filter_for_lookup(f, lookup_type)