From 4fc13ed307276cbf62ae39b0fb163e33880790fa Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 2 Mar 2021 02:35:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Create=20Sculptor=20module=20(mostl?= =?UTF-8?q?y=20empty)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- royalnet/sculptor/__init__.py | 5 +++++ royalnet/sculptor/a_base.py | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 royalnet/sculptor/__init__.py create mode 100644 royalnet/sculptor/a_base.py diff --git a/royalnet/sculptor/__init__.py b/royalnet/sculptor/__init__.py new file mode 100644 index 00000000..4117e111 --- /dev/null +++ b/royalnet/sculptor/__init__.py @@ -0,0 +1,5 @@ +""" +This module contains many :mod:`pydantic` models that may be useful to multiple projects. +""" + +from a_base import * diff --git a/royalnet/sculptor/a_base.py b/royalnet/sculptor/a_base.py new file mode 100644 index 00000000..f7b5dfd2 --- /dev/null +++ b/royalnet/sculptor/a_base.py @@ -0,0 +1,41 @@ +""" +Base models are :class:`pydantic.BaseModel` that have specific configuration tailored for certain uses. +""" + +import pydantic + + +class RoyalnetModel(pydantic.BaseModel): + """ + A model for generic data. + """ + + class Config(pydantic.BaseModel.Config): + """ + The default :mod:`pydantic` configuration. + + .. seealso:: `Pydantic Configuration `_, + :class:`pydantic.BaseModel.Config` + """ + pass + + +class OrmModel(RoyalnetModel): + """ + A model for :mod:`sqlalchemy` table data. + """ + + class Config(RoyalnetModel.Config): + """ + A configuration which allows for the loading of data from ``__getattr__`` instead of ``__getitem__``. + + .. seealso:: `Pydantic ORM Mode `_ + """ + orm_mode = True + + +__all__ = ( + "RoyalnetModel", + "OrmModel", +)