Skip to content

Django 1.6 compatibility #19

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion searchableselect/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
try:
# Django <=1.9
from django.db.models.loading import get_model

# Django 1.6.*
import django
if django.VERSION[0] == 1 and django.VERSION[1] == 6:
def get_model_wrapper(model):
get_model(*model.split('.'))

get_model = get_model_wrapper

except ImportError:
# Django 1.10+
from django.apps import apps
get_model = apps.get_model

from django.utils.encoding import smart_str
from django.http import JsonResponse
from django.http import HttpResponse

try:
from django.http import JsonResponse
except ImportError as e:
# Django < 1.7
from django.utils import simplejson
class JsonResponse(HttpResponse):
"""
JSON response
"""
def __init__(self, content, mimetype='application/json', status=None, content_type=None):
super(JsonResponse, self).__init__(
content=simplejson.dumps(content),
mimetype=mimetype,
status=status,
content_type=content_type,
)

from django.contrib.admin.views.decorators import staff_member_required


Expand Down
9 changes: 9 additions & 0 deletions searchableselect/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
try:
# Django <=1.9
from django.db.models.loading import get_model

# Django 1.6.*
import django
if django.VERSION[0] == 1 and django.VERSION[1] == 6:
def get_model_wrapper(model):
get_model(*model.split('.'))

get_model = get_model_wrapper

except ImportError:
# Django 1.10+
from django.apps import apps
Expand Down