diff --git a/simple_history/admin.py b/simple_history/admin.py index 4769a207e..271228b31 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -7,7 +7,10 @@ from django.contrib.contenttypes.models import ContentType from django.core.urlresolvers import reverse from django.shortcuts import get_object_or_404, render -from django.contrib.admin.util import unquote +try: + from django.contrib.admin.utils import unquote +except ImportError: + from django.contrib.admin.util import unquote from django.utils.text import capfirst from django.utils.html import mark_safe from django.utils.translation import ugettext as _ diff --git a/simple_history/management/commands/populate_history.py b/simple_history/management/commands/populate_history.py index c970f4a2d..600744090 100644 --- a/simple_history/management/commands/populate_history.py +++ b/simple_history/management/commands/populate_history.py @@ -1,7 +1,10 @@ from optparse import make_option from django.core.management.base import BaseCommand, CommandError -from django.db.models.loading import get_model - +try: + from django.apps import apps + get_model = apps.get_model +except (ImportError, AttributeError): # django 1.6 compatibility + from django.db.models.loading import get_model from ... import models from . import _populate_utils as utils diff --git a/simple_history/models.py b/simple_history/models.py index 588ff4c7f..fee46d427 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -6,12 +6,20 @@ import django from django.db import models, router -from django.db.models import loading +try: + from django.apps import apps + get_app = apps.get_app +except (ImportError, AttributeError): + from django.db.models.loading import get_app from django.db.models.fields.proxy import OrderWrt from django.db.models.fields.related import RelatedField from django.conf import settings from django.contrib import admin -from django.utils import importlib, six +try: + import importlib +except ImportError: + from django.utils import importlib +from django.utils import six from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import smart_text from django.utils.timezone import now @@ -99,7 +107,7 @@ def create_history_model(self, model): elif app_module != self.module: if apps is None: # Django < 1.7 # has meta options with app_label - app = loading.get_app(model._meta.app_label) + app = get_app(model._meta.app_label) attrs['__module__'] = app.__name__ # full dotted name else: # Abuse an internal API because the app registry is loading. diff --git a/simple_history/tests/tests/test_admin.py b/simple_history/tests/tests/test_admin.py index 66ae4d079..5e547343f 100644 --- a/simple_history/tests/tests/test_admin.py +++ b/simple_history/tests/tests/test_admin.py @@ -8,7 +8,10 @@ User = get_user_model() except ImportError: # django 1.4 compatibility from django.contrib.auth.models import User -from django.contrib.admin.util import quote +try: + from django.contrib.admin.utils import quote +except ImportError: # django 1.7 compatibility + from django.contrib.admin.util import quote from django.conf import settings from simple_history.models import HistoricalRecords