Skip to content
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

Add support for Django 2.0 #509

Merged
merged 1 commit into from
Dec 20, 2017
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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ matrix:
env: TOXENV=py35-1.11.x
- python: 3.6
env: TOXENV=py36-1.11.x
- python: 3.4
env: TOXENV=py34-2.0.x
- python: 3.5
env: TOXENV=py35-2.0.x
- python: 3.6
env: TOXENV=py36-2.0.x
- python: 3.4
env: TOXENV=py34-master
- python: 3.5
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
Expand Down
65 changes: 47 additions & 18 deletions taggit/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, field, related_name, through, to=None):
else:
self.to = to
self.related_name = related_name
self.related_query_name = None
self.limit_choices_to = {}
self.symmetrical = True
self.multiple = True
Expand Down Expand Up @@ -118,11 +119,23 @@ def get_prefetch_queryset(self, instances, queryset=None):
'_prefetch_related_val': '%s.%s' % (qn(join_table), qn(source_col))
}
)
return (qs,
if VERSION < (2, 0):
return (
qs,
attrgetter('_prefetch_related_val'),
lambda obj: obj._get_pk_val(),
False,
self.prefetch_cache_name)
self.prefetch_cache_name,
)
else:
return (
qs,
attrgetter('_prefetch_related_val'),
lambda obj: obj._get_pk_val(),
False,
self.prefetch_cache_name,
False,
)

def _lookup_kwargs(self):
return self.through.lookup_kwargs(self.instance)
Expand Down Expand Up @@ -586,46 +599,62 @@ def get_extra_join_sql(self, connection, qn, lhs_alias, rhs_alias):
params = content_type_ids
return extra_where, params

def _get_mm_case_path_info(self, direct=False):
def _get_mm_case_path_info(self, direct=False, filtered_relation=None):
pathinfos = []
linkfield1 = self.through._meta.get_field('content_object')
linkfield2 = self.through._meta.get_field(self.m2m_reverse_field_name())
if direct:
join1infos = linkfield1.get_reverse_path_info()
join2infos = linkfield2.get_path_info()
if VERSION < (2, 0):
join1infos = linkfield1.get_reverse_path_info()
join2infos = linkfield2.get_path_info()
else:
join1infos = linkfield1.get_reverse_path_info(filtered_relation=filtered_relation)
join2infos = linkfield2.get_path_info(filtered_relation=filtered_relation)
else:
join1infos = linkfield2.get_reverse_path_info()
join2infos = linkfield1.get_path_info()
if VERSION < (2, 0):
join1infos = linkfield2.get_reverse_path_info()
join2infos = linkfield1.get_path_info()
else:
join1infos = linkfield2.get_reverse_path_info(filtered_relation=filtered_relation)
join2infos = linkfield1.get_path_info(filtered_relation=filtered_relation)
pathinfos.extend(join1infos)
pathinfos.extend(join2infos)
return pathinfos

def _get_gfk_case_path_info(self, direct=False):
def _get_gfk_case_path_info(self, direct=False, filtered_relation=None):
pathinfos = []
from_field = self.model._meta.pk
opts = self.through._meta
linkfield = self.through._meta.get_field(self.m2m_reverse_field_name())
if direct:
join1infos = [PathInfo(self.model._meta, opts, [from_field], _remote_field(self), True, False)]
join2infos = linkfield.get_path_info()
if VERSION < (2, 0):
join1infos = [PathInfo(self.model._meta, opts, [from_field], _remote_field(self), True, False)]
join2infos = linkfield.get_path_info()
else:
join1infos = [PathInfo(self.model._meta, opts, [from_field], _remote_field(self), True, False, filtered_relation)]
join2infos = linkfield.get_path_info(filtered_relation=filtered_relation)
else:
join1infos = linkfield.get_reverse_path_info()
join2infos = [PathInfo(opts, self.model._meta, [from_field], self, True, False)]
if VERSION < (2, 0):
join1infos = linkfield.get_reverse_path_info()
join2infos = [PathInfo(opts, self.model._meta, [from_field], self, True, False)]
else:
join1infos = linkfield.get_reverse_path_info(filtered_relation=filtered_relation)
join2infos = [PathInfo(opts, self.model._meta, [from_field], self, True, False, filtered_relation)]
pathinfos.extend(join1infos)
pathinfos.extend(join2infos)
return pathinfos

def get_path_info(self):
def get_path_info(self, filtered_relation=None):
if self.use_gfk:
return self._get_gfk_case_path_info(direct=True)
return self._get_gfk_case_path_info(direct=True, filtered_relation=filtered_relation)
else:
return self._get_mm_case_path_info(direct=True)
return self._get_mm_case_path_info(direct=True, filtered_relation=filtered_relation)

def get_reverse_path_info(self):
def get_reverse_path_info(self, filtered_relation=None):
if self.use_gfk:
return self._get_gfk_case_path_info(direct=False)
return self._get_gfk_case_path_info(direct=False, filtered_relation=filtered_relation)
else:
return self._get_mm_case_path_info(direct=False)
return self._get_mm_case_path_info(direct=False, filtered_relation=filtered_relation)

def get_joining_columns(self, reverse_join=False):
if reverse_join:
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ envlist =
{py27,py34,py35}-1.9.x
{py27,py34,py35}-1.10.x
{py27,py34,py35,py36}-1.11.x
{py34,py35,py36}-2.0.x
{py34,py35,py36}-master

[testenv]
Expand All @@ -12,6 +13,7 @@ deps =
1.9.x: https://github.com/django/django/archive/stable/1.9.x.tar.gz#egg=django
1.10.x: https://github.com/django/django/archive/stable/1.10.x.tar.gz#egg=django
1.11.x: https://github.com/django/django/archive/stable/1.11.x.tar.gz#egg=django
2.0.x: https://github.com/django/django/archive/stable/2.0.x.tar.gz#egg=django
master: https://github.com/django/django/archive/master.tar.gz#egg=django
commands =
make develop test
Expand Down