def nested_model(model, nested_fields):
<EOL>if model is None:<EOL><INDENT>return None<EOL><DEDENT>app_model = model.get_app_model()<EOL>is_dict = isinstance(nested_fields, dict)<EOL>for field in nested_fields:<EOL><INDENT>field = get_nested_field_name(field)<EOL>nested_nested = nested_fields.get(<EOL>field) if is_dict and nested_fields.get(field) else []<EOL>value = getattr(model, field, None)<EOL>nm_fn = nested_models if isinstance(value, list) else nested_model<EOL>setattr(app_model, field, nm_fn(value, nested_nested))<EOL><DEDENT>return app_model<EOL>
Return :class:`zsl.db.model.app_model import AppModel` with the nested
models attached. ``nested_fields`` can be a simple list as model
fields, or it can be a tree definition in dict with leafs as keys with
``None`` value