'Dynamically serialize obj using serializers passed through the context,
depending on the doc_type of the obj.'

def to_representation(self, obj):

    if hasattr(obj, '_meta'):
        doc_type = obj._meta['doc_type']
    else:
        doc_type = obj['_type']
    serializer = self.serializers.get(doc_type)
    if (serializer is None):
        return super(DynamicSearchSerializer, self).to_representation(obj)
    data = serializer.to_representation(obj)
    data['doc_type'] = doc_type
    return data
