From 09648fa29274de1d33859d309e295594af0e3e5e Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Sun, 28 Sep 2025 02:12:14 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20pydantic=20model=20and=20readonl?= =?UTF-8?q?y=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ohmyapi/db/model/model.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ohmyapi/db/model/model.py b/src/ohmyapi/db/model/model.py index d005e43..eb0b504 100644 --- a/src/ohmyapi/db/model/model.py +++ b/src/ohmyapi/db/model/model.py @@ -12,7 +12,7 @@ class ModelMeta(type(TortoiseModel)): class BoundSchema: @property def model(self): - """Return a Pydantic model class for 'one' results.""" + """Return a Pydantic model class for serializing results.""" include = getattr(schema_opts, "include", None) exclude = getattr(schema_opts, "exclude", None) return pydantic_model_creator( @@ -20,6 +20,18 @@ class ModelMeta(type(TortoiseModel)): name=f"{new_cls.__name__}Schema", include=include, exclude=exclude, + ) + + @property + def readonly(self): + """Return a Pydantic model class for serializing readonly results.""" + include = getattr(schema_opts, "include", None) + exclude = getattr(schema_opts, "exclude", None) + return pydantic_model_creator( + new_cls, + name=f"{new_cls.__name__}SchemaReadonly", + include=include, + exclude=exclude, exclude_readonly=True, )