Skip to content

Instantly share code, notes, and snippets.

@muhammad-ammar
Created September 3, 2015 09:14
Show Gist options
  • Save muhammad-ammar/fc51cd60e7f664680084 to your computer and use it in GitHub Desktop.
Save muhammad-ammar/fc51cd60e7f664680084 to your computer and use it in GitHub Desktop.
load get_model when needed
get_model_func = None
def get_model(app, model):
if get_model_func is None:
if django is None:
raise import_failure
elif django.VERSION[:2] < (1, 7):
from django.db.models import loading
get_model_func = loading.get_model()
else:
from django import apps as django_apps
get_model_func = django_apps.apps.get_model
get_model_func(app, model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment