def get_owner(page_instance): from helpers import object_to_dict owner = page_instance.owner if owner is None: return None fields = get_model_default_readable_fields(User) return object_to_dict(owner, fields)
def _get_related(instance, related_name, model): """ Returns dicts of all `model` objects attached to `instance` via the `related_name` ORM relation. """ from helpers import object_to_dict related_objects = getattr(instance, related_name).all() fields = get_model_default_readable_fields(model) return [object_to_dict(o, fields) for o in related_objects]