From 009941aaddaccccff51cf3e6b35617ed920428c1 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 15 Jun 2017 10:40:24 -0400 Subject: [PATCH 1/4] conditionally using GenericForeignKey only when contenttypes is installed app --- url_filter/filtersets/django.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/url_filter/filtersets/django.py b/url_filter/filtersets/django.py index 1f8421b..df4c5f2 100644 --- a/url_filter/filtersets/django.py +++ b/url_filter/filtersets/django.py @@ -3,7 +3,7 @@ import operator from django import forms -from django.contrib.contenttypes.fields import GenericForeignKey +from django.conf import settings from django.db import models from django.db.models.fields.related import ForeignObjectRel, RelatedField @@ -16,6 +16,13 @@ __all__ = ['ModelFilterSet', 'DjangoModelFilterSetOptions'] +GenericForeignKey = None + + +if 'django.contrib.contenttypes' in settings.INSTALLED_APPS: + from django.contrib.contenttypes.fields import GenericForeignKey + + MODEL_FIELD_OVERWRITES = SubClassDict({ models.AutoField: forms.IntegerField(min_value=0), models.FileField: lambda m: forms.CharField(max_length=m.max_length), @@ -95,7 +102,7 @@ def _build_filter(self, name, state): raise SkipFilter return self._build_filterset_from_reverse_field(field) - elif isinstance(field, GenericForeignKey): + elif GenericForeignKey and isinstance(field, GenericForeignKey): raise SkipFilter else: From 489d30cceefe32afb90cc7c483757b86e684909e Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 15 Jun 2017 10:43:27 -0400 Subject: [PATCH 2/4] bumping version to 0.3.3 --- HISTORY.rst | 7 +++++++ url_filter/__init__.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 072ec6a..37f2d29 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,13 @@ History ------- +0.3.3 (2017-06-15) +~~~~~~~~~~~~~~~~~~ + +* Fixed bug which did not allow to use SQLAlchemy backend fully + without having ``django.contrib.contenttypes`` in installed apps. + See `#36 `_. + 0.3.2 (2017-05-19) ~~~~~~~~~~~~~~~~~~ diff --git a/url_filter/__init__.py b/url_filter/__init__.py index a725b33..7762f3f 100644 --- a/url_filter/__init__.py +++ b/url_filter/__init__.py @@ -4,4 +4,4 @@ __author__ = 'Miroslav Shubernetskiy' __email__ = 'miroslav@miki725.com' -__version__ = '0.3.2' +__version__ = '0.3.3' From 02727864ef197fb3a74566565cfc86d86dc22edb Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 15 Jun 2017 11:20:02 -0400 Subject: [PATCH 3/4] improved different versions SQLAlchemy compatibility --- url_filter/backends/sqlalchemy.py | 2 +- url_filter/integrations/drf.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/url_filter/backends/sqlalchemy.py b/url_filter/backends/sqlalchemy.py index 09c3a82..39a94ba 100644 --- a/url_filter/backends/sqlalchemy.py +++ b/url_filter/backends/sqlalchemy.py @@ -66,7 +66,7 @@ def get_model(self): """ Get the model from the given queryset """ - return self.queryset._primary_entity.entities[0] + return self.queryset._only_entity_zero().mapper.class_ def filter_by_specs(self, queryset): """ diff --git a/url_filter/integrations/drf.py b/url_filter/integrations/drf.py index d65e868..3957fc5 100644 --- a/url_filter/integrations/drf.py +++ b/url_filter/integrations/drf.py @@ -162,3 +162,6 @@ def filter_queryset(self, request, queryset, view): raise ValidationError(e.message_dict) return queryset + + +URLFilterBackend = DjangoFilterBackend From a1416e19899ca98ba6accbfa671295250a3754bf Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 15 Jun 2017 11:21:26 -0400 Subject: [PATCH 4/4] added notes to HISTORY.rst --- HISTORY.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 37f2d29..cff4ca7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -9,6 +9,9 @@ History * Fixed bug which did not allow to use SQLAlchemy backend fully without having ``django.contrib.contenttypes`` in installed apps. See `#36 `_. +* Improved SQLAlchemy versions compatibility. +* Added ``URLFilterBackend`` alias in DRF integration for backend to reduce + confusion with ``DjangoFilterBackend`` as in url filter core backend. 0.3.2 (2017-05-19) ~~~~~~~~~~~~~~~~~~