Fix compatibility with older Django versions
parent
3817061467
commit
10ab3ad14c
|
|
@ -1,8 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import django
|
||||
import re
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.six import python_2_unicode_compatible
|
||||
|
||||
try:
|
||||
from django.utils.six import python_2_unicode_compatible
|
||||
except ImportError:
|
||||
from django.utils.encoding import python_2_unicode_compatible # Django 1.5
|
||||
|
||||
RE_DEFERRED = re.compile('_Deferred_.*')
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
|
|
@ -95,7 +102,7 @@ class ShowFieldBase(object):
|
|||
# ( bool: new section , item-text , separator to use after item )
|
||||
|
||||
# start with model name
|
||||
parts = [(True, self._meta.object_name, ':')]
|
||||
parts = [(True, RE_DEFERRED.sub('', self.__class__.__name__), ':')]
|
||||
|
||||
# add all regular fields
|
||||
self._showfields_add_regular_fields(parts)
|
||||
|
|
@ -152,8 +159,8 @@ class ShowFieldBase(object):
|
|||
|
||||
if django.VERSION < (1, 8):
|
||||
def get_deferred_fields(self):
|
||||
from django.db.models import DeferredAttribute
|
||||
return set(attr for attr, value in self.__class__ if isinstance(value, DeferredAttribute))
|
||||
from django.db.models.query_utils import DeferredAttribute
|
||||
return set(attr for attr, value in self.__class__.__dict__.items() if isinstance(value, DeferredAttribute))
|
||||
|
||||
|
||||
class ShowFieldType(ShowFieldBase):
|
||||
|
|
|
|||
|
|
@ -1139,10 +1139,11 @@ class PolymorphicTests(TestCase):
|
|||
self.assertEqual(result, {'cnt': 2})
|
||||
|
||||
# aggregate using **args
|
||||
with self.assertRaisesMessage(AssertionError, 'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only'):
|
||||
Model2A.objects.aggregate(Count('Model2B___field2'))
|
||||
|
||||
|
||||
self.assertRaisesMessage(
|
||||
AssertionError,
|
||||
'PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only',
|
||||
lambda: Model2A.objects.aggregate(Count('Model2B___field2'))
|
||||
)
|
||||
|
||||
@skipIf(django.VERSION < (1,8,), "This test needs Django >=1.8")
|
||||
def test_polymorphic__complex_aggregate(self):
|
||||
|
|
@ -1294,7 +1295,7 @@ def qrepr(data):
|
|||
"""
|
||||
Ensure consistent repr() output for the QuerySet object.
|
||||
"""
|
||||
if isinstance(data, models.QuerySet):
|
||||
if isinstance(data, QuerySet):
|
||||
if django.VERSION >= (1, 10):
|
||||
return repr(data)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue