From 79f45e2d080abad5441d6d7fa3052ec19f19bfd7 Mon Sep 17 00:00:00 2001 From: Jared Proffitt Date: Wed, 2 Sep 2015 09:17:42 -0500 Subject: [PATCH] Fixing RemovedInDjango19Warning related to get_model. fixes issue #6 --- swapper/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/swapper/__init__.py b/swapper/__init__.py index 51ac944..b35fa16 100644 --- a/swapper/__init__.py +++ b/swapper/__init__.py @@ -76,10 +76,17 @@ def load_model(app_label, model, orm=None, required=True): if orm is not None: return orm[join(app_label, model)] - from django.db.models import get_model try: - cls = get_model(app_label, model) + try: + # django >= 1.7 + from django.apps import apps + cls = apps.get_model(app_label, model) + except ImportError: + # django < 1.7 + from django.db.models import get_model + cls = get_model(app_label, model) except LookupError: + # both get_model versions can raise a LookupError cls = None if cls is None and required: