mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-04-23 02:22:08 +03:00
Drop support for django-filter < 2
It was only needed for Python 2.7
This commit is contained in:
parent
15775712be
commit
ddacb9d4e8
|
@ -2,9 +2,8 @@ Filtering
|
|||
=========
|
||||
|
||||
Graphene integrates with
|
||||
`django-filter <https://django-filter.readthedocs.io/en/master/>`__ (2.x for
|
||||
Python 3 or 1.x for Python 2) to provide filtering of results. See the `usage
|
||||
documentation <https://django-filter.readthedocs.io/en/master/guide/usage.html#the-filter>`__
|
||||
`django-filter <https://django-filter.readthedocs.io/en/master/>`__ to provide filtering of results.
|
||||
See the `usage documentation <https://django-filter.readthedocs.io/en/master/guide/usage.html#the-filter>`__
|
||||
for details on the format for ``filter_fields``.
|
||||
|
||||
This filtering is automatically available when implementing a ``relay.Node``.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import itertools
|
||||
|
||||
from django.db import models
|
||||
from django_filters import Filter, MultipleChoiceFilter, VERSION
|
||||
from django_filters import Filter, MultipleChoiceFilter
|
||||
from django_filters.filterset import BaseFilterSet, FilterSet
|
||||
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS
|
||||
|
||||
|
@ -50,36 +50,6 @@ class GrapheneFilterSetMixin(BaseFilterSet):
|
|||
)
|
||||
|
||||
|
||||
# To support a Django 1.11 + Python 2.7 combination django-filter must be
|
||||
# < 2.x.x. To support the earlier version of django-filter, the
|
||||
# filter_for_reverse_field method must be present on GrapheneFilterSetMixin and
|
||||
# must not be present for later versions of django-filter.
|
||||
if VERSION[0] < 2:
|
||||
from django.utils.text import capfirst
|
||||
|
||||
class GrapheneFilterSetMixinPython2(GrapheneFilterSetMixin):
|
||||
@classmethod
|
||||
def filter_for_reverse_field(cls, f, name):
|
||||
"""Handles retrieving filters for reverse relationships
|
||||
We override the default implementation so that we can handle
|
||||
Global IDs (the default implementation expects database
|
||||
primary keys)
|
||||
"""
|
||||
try:
|
||||
rel = f.field.remote_field
|
||||
except AttributeError:
|
||||
rel = f.field.rel
|
||||
default = {"name": name, "label": capfirst(rel.related_name)}
|
||||
if rel.multiple:
|
||||
# For to-many relationships
|
||||
return GlobalIDMultipleChoiceFilter(**default)
|
||||
else:
|
||||
# For to-one relationships
|
||||
return GlobalIDFilter(**default)
|
||||
|
||||
GrapheneFilterSetMixin = GrapheneFilterSetMixinPython2
|
||||
|
||||
|
||||
def setup_filterset(filterset_class):
|
||||
""" Wrap a provided filterset in Graphene-specific functionality
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user