Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.0.4 #723

Merged
merged 5 commits into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.3
current_version = 1.0.4
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
Expand Down
12 changes: 9 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Version 1.0.3 (2107-05-16)
Version 1.0.4 (2017-05-19)
--------------------------

Improves compatibility with Django REST Framework schema generation.
Quick fix for verbose_field_name issue from 1.0.3 (#722)

See the `1.0.2 Milestone`__ for full details.

Version 1.0.3 (2017-05-16)
--------------------------

Improves compatibility with Django REST Framework schema generation.

See the `1.0.3 Milestone`__ for full details.

__ https://github.com/carltongibson/django-filter/milestone/13?closed=1

Expand Down
29 changes: 18 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Django Filter
=============

Django-filter is a reusable Django application for allowing users to filter
querysets dynamically.
Django-filter is a reusable Django application allowing users to declaratively
add dynamic ``QuerySet`` filtering from URL parameters.

Full documentation on `read the docs`_.

Expand Down Expand Up @@ -68,22 +68,28 @@ And then in your view you could do:
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:

Usage with Django REST Framework
--------------------------------

Django-filter provides a custom ``FilterSet`` and filter backend for use with
Django REST Framework.

To use this adjust your import to use
``django_filters.rest_framework.FilterSet``.

.. code-block:: python

import django_filters
from django_filters import rest_framework as filters

class ProductFilter(django_filters.FilterSet):
class ProductFilter(filters.FilterSet):
class Meta:
model = Product
fields = {'name': ['exact', 'icontains'],
'price': ['exact', 'gte', 'lte'],
}
fields = ('category', 'in_stock')


For more details see the `DRF integration docs`_.

The filters will be available as ``'name'``, ``'name__icontains'``,
``'price'``, ``'price__gte'``, and ``'price__lte'`` in the above example.

Support
-------
Expand All @@ -93,3 +99,4 @@ If you have questions about usage or development you can join the

.. _`read the docs`: https://django-filter.readthedocs.io/en/develop/
.. _`mailing list`: http://groups.google.com/group/django-filter
.. _`DRF integration docs`: https://django-filter.readthedocs.io/en/develop/guide/rest_framework.html
2 changes: 1 addition & 1 deletion django_filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
except ImportError:
rest_framework = None

__version__ = '1.0.3'
__version__ = '1.0.4'


def parse_version(version):
Expand Down
5 changes: 4 additions & 1 deletion django_filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def verbose_field_name(model, field_name):
names = []
for part in parts:
if isinstance(part, ForeignObjectRel):
names.append(part.related_name.replace('_', ' '))
if part.related_name:
names.append(part.related_name.replace('_', ' '))
else:
return '[invalid name]'
else:
names.append(force_text(part.verbose_name))

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = '1.0.3'
version = '1.0.4'
# The full version, including alpha/beta/rc tags.
release = '1.0.3'
release = '1.0.4'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
readme = f.read()
f.close()

version = '1.0.3'
version = '1.0.4'

if sys.argv[-1] == 'publish':
if os.system("pip freeze | grep wheel"):
Expand Down
36 changes: 30 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
verbose_field_name, verbose_lookup_expr, label_for_filter, raw_validation,
)

from .models import User
from .models import Article
from .models import Book
from .models import HiredWorker
from .models import Business
from .models import NetworkSetting
from .models import (
User,
Article,
Book,
HiredWorker,
Business,
NetworkSetting,
Company,
Account,
)


class GetFieldPartsTests(TestCase):
Expand Down Expand Up @@ -253,6 +257,26 @@ def test_lazy_text(self):
verbose_name = verbose_field_name(User, 'username')
self.assertEqual(verbose_name, 'username')

def test_forwards_fk(self):
verbose_name = verbose_field_name(Article, 'author')
self.assertEqual(verbose_name, 'author')

def test_backwards_fk(self):
# https://github.com/carltongibson/django-filter/issues/716

# related_name is set
verbose_name = verbose_field_name(Company, 'locations')
self.assertEqual(verbose_name, 'locations')

# related_name not set. Auto-generated relation is `article_set`
# _meta.get_field raises FieldDoesNotExist
verbose_name = verbose_field_name(User, 'article_set')
self.assertEqual(verbose_name, '[invalid name]')

# WRONG NAME! Returns ManyToOneRel with related_name == None.
verbose_name = verbose_field_name(User, 'article')
self.assertEqual(verbose_name, '[invalid name]')


class VerboseLookupExprTests(TestCase):

Expand Down