Returns a Django model instance, using a document from Elasticsearch

def from_es(self, hit):
        """Returns a Django model instance, using a document from Elasticsearch"""
        doc = hit.copy()
        klass = shallow_class_factory(self.model)

        # We can pass in the entire source, except when we have a non-indexable many-to-many
        for field in self.model._meta.get_fields():

            if not field.auto_created and field.many_to_many:
                if not issubclass(field.rel.to, Indexable):
                    if field.name in doc["_source"]:
                        del doc["_source"][field.name]

            # if field.one_to_many:
            #     if field.name in doc["_source"]:
            #         del doc["_source"][field.name]

        # Now let's go ahead and parse all the fields
        fields = self.mapping.properties.properties
        for key in fields:
            # TODO: What if we've mapped the property to a different name? Will we allow that?
            field = fields[key]

            # if isinstance(field, InnerObject):
            #     import pdb; pdb.set_trace()
            #     continue

            if doc["_source"].get(key):
                attribute_value = doc["_source"][key]

                doc["_source"][key] = field.to_python(attribute_value)

        return klass(**doc["_source"])