mirror of
https://github.com/bringout/oca-technical.git
synced 2026-04-18 21:32:00 +02:00
Initial commit: OCA Technical packages (595 packages)
This commit is contained in:
commit
2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
To support pydantic models that map to Odoo models, Pydantic model instances can
|
||||
be created from arbitrary odoo model instances by mapping fields from odoo
|
||||
models to fields defined by the pydantic model. To ease the mapping, the addon
|
||||
provide a utility class `odoo.addons.pydantic.utils.GenericOdooGetter`.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import pydantic
|
||||
from odoo.addons.pydantic import utils
|
||||
|
||||
class Group(pydantic.BaseModel):
|
||||
name: str
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
getter_dict = utils.GenericOdooGetter
|
||||
|
||||
class UserInfo(pydantic.BaseModel):
|
||||
name: str
|
||||
groups: List[Group] = pydantic.Field(alias="groups_id")
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
getter_dict = utils.GenericOdooGetter
|
||||
|
||||
user = self.env.user
|
||||
user_info = UserInfo.from_orm(user)
|
||||
|
||||
See the official `Pydantic documentation`_ to discover all the available functionalities.
|
||||
|
||||
.. _`Pydantic documentation`: https://pydantic-docs.helpmanual.io/
|
||||
Loading…
Add table
Add a link
Reference in a new issue