{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "
You are looking at an HTML rendering of the generated widgets, they are lacking responsiveness due to no Python kernel being available for callbacks.
" ] }, { "cell_type": "markdown", "id": "1", "metadata": {}, "source": [ "# Inline Editing with PydanticEditorMixin" ] }, { "cell_type": "markdown", "id": "2", "metadata": {}, "source": [ "Use `PydanticEditorMixin` to attach an Edit/Save/Cancel toolbar to model instances." ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "from pydantic import BaseModel, Field\n", "from ipywidgets_jsonschema import PydanticEditorMixin\n", "\n", "\n", "class SessionPreferences(PydanticEditorMixin, BaseModel):\n", " username: str = \"student01\"\n", " autosave: bool = True\n", " refresh_interval_s: int = Field(30, ge=5, le=300)\n", "\n", "\n", "preferences = SessionPreferences()\n", "preferences.edit()" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "preferences.model_dump()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3" } }, "nbformat": 4, "nbformat_minor": 5 }