def simplify_model(obj, terse=False):
    if obj is None:
        return None
    # It's a Model instance
    # "expose_fields" is never used
    if hasattr(obj._meta, 'expose_fields'):
        expose_fields = obj._meta.expose_fields
    else:
        expose_fields = [f.name for f in obj._meta.fields]
    out = {
        '_type': '%s.%s' % (obj.__module__[:-7], obj._meta.object_name),
        '_pk': obj.pk,
    }
    if hasattr(obj, 'get_absolute_url'):
        out['_url'] = obj.get_absolute_url()
    if terse:
        out['_terse'] = True
    else:
        for field_name in expose_fields:
            if field_name in FIELDS_NOT_EXPOSED:
                continue
            try:
                value = getattr(obj, field_name)
                if isinstance(value, models.Model):
                    value = simplify_model(value, terse=True)
                out[field_name] = simplify_value(value)
            except __HOLE__:
                pass

        # Add any non-field attributes
        for field in list(dir(obj)):
            try:
                if field[0] != '_' and field != 'objects' \
                        and not isinstance(getattr(obj, field), models.Field) \
                        and not field in FIELDS_NOT_EXPOSED:
                    try:
                        out[field] = simplify_value(getattr(obj, field))
                    except NotImplementedError:
                        pass
            except AttributeError:
                pass
    return out
dataset/ETHPy150Open mollyproject/mollyproject/molly/utils/simplify.py/simplify_model