diff --git a/.travis.yml b/.travis.yml index 6a8073df..1b79bc79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python python: - 3.7 - 3.8 + - 3.9 services: - postgresql - mysql @@ -15,6 +16,9 @@ env: - DJANGO=3.0 DATABASE_ENGINE=sqlite - DJANGO=3.0 DATABASE_ENGINE=postgres - DJANGO=3.0 DATABASE_ENGINE=mysql + - DJANGO=4.0 DATABASE_ENGINE=sqlite + - DJANGO=4.0 DATABASE_ENGINE=postgres + - DJANGO=4.0 DATABASE_ENGINE=mysql install: - pip install -U setuptools zc.buildout diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 88994348..6a104b4c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -9,7 +9,7 @@ Version 0.5.0, 6th March 2020: * Compatiblity fix for Django 2.2 and Django 3.0. Version 0.4.6, 14th October 2017: --------------------------------- +--------------------------------- * Fix IntegrityError while saving inconsistent tags * Update tag name length to use MAX_TAG_LENGTH setting diff --git a/tagging/models.py b/tagging/models.py index 02550eec..50995c8d 100644 --- a/tagging/models.py +++ b/tagging/models.py @@ -5,7 +5,8 @@ from django.contrib.contenttypes.models import ContentType from django.db import connection from django.db import models -from django.utils.encoding import smart_text +from django.db.models.query_utils import Q +from django.utils.encoding import smart_str from django.utils.translation import gettext_lazy as _ from tagging import settings @@ -155,8 +156,9 @@ def usage_for_model(self, model, counts=False, min_count=None, filters = {} queryset = model._default_manager.filter() - for f in filters.items(): - queryset.query.add_filter(f) + for k, v in filters.items(): + # Add support for both Django 4 and inferior versions + queryset.query.add_q(Q((k, v))) usage = self.usage_for_queryset(queryset, counts, min_count) return usage @@ -519,4 +521,4 @@ class Meta: verbose_name_plural = _('tagged items') def __str__(self): - return '%s [%s]' % (smart_text(self.object), smart_text(self.tag)) + return '%s [%s]' % (smart_str(self.object), smart_str(self.tag)) diff --git a/tagging/tests/urls.py b/tagging/tests/urls.py index aa127d5f..7db3e7e1 100644 --- a/tagging/tests/urls.py +++ b/tagging/tests/urls.py @@ -1,5 +1,5 @@ """Test urls for tagging.""" -from django.conf.urls import url +from django.urls import re_path from tagging.tests.models import Article from tagging.views import TaggedObjectList @@ -11,10 +11,10 @@ class StaticTaggedObjectList(TaggedObjectList): urlpatterns = [ - url(r'^static/$', StaticTaggedObjectList.as_view()), - url(r'^static/related/$', StaticTaggedObjectList.as_view( + re_path(r'^static/$', StaticTaggedObjectList.as_view()), + re_path(r'^static/related/$', StaticTaggedObjectList.as_view( related_tags=True)), - url(r'^no-tag/$', TaggedObjectList.as_view(model=Article)), - url(r'^no-query-no-model/$', TaggedObjectList.as_view()), - url(r'^(?P[^/]+(?u))/$', TaggedObjectList.as_view(model=Article)), + re_path(r'^no-tag/$', TaggedObjectList.as_view(model=Article)), + re_path(r'^no-query-no-model/$', TaggedObjectList.as_view()), + re_path(r'^(?P[^/]+(?u))/$', TaggedObjectList.as_view(model=Article)), ]