def to_python(self, val, parent=None):
        if self.self_reference:
            if val is None:
                return val
            document = type(parent)
            if isinstance(val, document):
                return val
        else:
            if self.is_instance(val):
                return val
            document = self.document
        try:
            if isinstance(val, dict):
                return document.objects.get_by_natural_key(**val)
            return document.objects.get(pk=val)
        except __HOLE__:
            if self.null:
                return None
            raise
dataset/ETHPy150Open zbyte64/django-dockit/dockit/schema/fields.py/ReferenceField.to_python