Skip to content

Commit

Permalink
Merge pull request #1 from ignacionf/master
Browse files Browse the repository at this point in the history
  • Loading branch information
MightySCollins authored Jun 26, 2017
2 parents 302d8d0 + 8fa395c commit 902948b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 16 additions & 6 deletions django_elasticsearch/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,22 @@ def check_cluster(self):

def get_serializer(self, **kwargs):
serializer = self.model.Elasticsearch.serializer_class
if isinstance(serializer, basestring):
module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
mod = importlib.import_module(module)
return getattr(mod, kls)(self.model, **kwargs)
else:
return serializer(self.model, **kwargs)

# python 2.x
try:
if isinstance(serializer, basestring):
module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
mod = importlib.import_module(module)
return getattr(mod, kls)(self.model, **kwargs)

# python 3.x
except NameError:
if isinstance(serializer, str):
module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
mod = importlib.import_module(module)
return getattr(mod, kls)(self.model, **kwargs)

return serializer(self.model, **kwargs)

@needs_instance
def serialize(self):
Expand Down
7 changes: 7 additions & 0 deletions django_elasticsearch/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
from django.db.models import FieldDoesNotExist
from django.db.models.fields.related import ManyToManyField

try:
# python 2.x
UNICODE_PY2X = bool(type(unicode))
except NameError:
# python 3.x
unicode = lambda s: str(s)


class EsSerializer(object):
def serialize(self, instance):
Expand Down

0 comments on commit 902948b

Please sign in to comment.