Skip to content

Add support for Django4 #23

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
python:
- 3.7
- 3.8
- 3.9
services:
- postgresql
- mysql
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions tagging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
12 changes: 6 additions & 6 deletions tagging/tests/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<tag>[^/]+(?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<tag>[^/]+(?u))/$', TaggedObjectList.as_view(model=Article)),
]