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

Compatibility with 1.7 & 1.8a1 #21

Merged
merged 4 commits into from
Jan 24, 2015
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
5 changes: 4 additions & 1 deletion genericm2m/genericm2m_tests/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from django.contrib.contenttypes.generic import GenericForeignKey
try:
from django.contrib.contenttypes.fields import GenericForeignKey
except ImportError:
from django.contrib.contenttypes.generic import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models

Expand Down
15 changes: 11 additions & 4 deletions genericm2m/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
from django.contrib.contenttypes.generic import GenericForeignKey
import django
try:
from django.contrib.contenttypes.fields import GenericForeignKey
except ImportError:
from django.contrib.contenttypes.generic import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import Q
Expand Down Expand Up @@ -127,12 +131,15 @@ def create_manager(self, instance, superclass, cf_from=True):
uses_gfk = self.is_gfk(rel_field)

class RelatedManager(superclass):
def get_query_set(self):
def get_queryset(self):
if uses_gfk:
qs = GFKOptimizedQuerySet(self.model, gfk_field=rel_field)
return qs.filter(**(core_filters))
else:
return superclass.get_query_set(self).filter(**(core_filters))
return superclass.get_queryset(self).filter(**(core_filters))

if django.VERSION < (1, 6):
get_query_set = get_queryset

def add(self, *objs):
for obj in objs:
Expand Down Expand Up @@ -183,7 +190,7 @@ def related_to(self):
)

def symmetrical(self):
return superclass.get_query_set(self).filter(
return superclass.get_queryset(self).filter(
Q(**rel_obj.get_query_from(instance)) |
Q(**rel_obj.get_query_to(instance))
).distinct()
Expand Down
2 changes: 2 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
'genericm2m',
'genericm2m.genericm2m_tests',
],
MIDDLEWARE_CLASSES = (),
)

from django.test.utils import get_runner

django.setup()

def runtests(*test_args):
if not test_args:
Expand Down