Skip to content
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
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
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 <https://github.com/miki725/django-url-filter/issues/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)
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion url_filter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = 'Miroslav Shubernetskiy'
__email__ = 'miroslav@miki725.com'
__version__ = '0.3.2'
__version__ = '0.3.3'
2 changes: 1 addition & 1 deletion url_filter/backends/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
11 changes: 9 additions & 2 deletions url_filter/filtersets/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions url_filter/integrations/drf.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,6 @@ def filter_queryset(self, request, queryset, view):
raise ValidationError(e.message_dict)

return queryset


URLFilterBackend = DjangoFilterBackend