pydantic
create_pydantic_field(field_name, model, model_field)
Registers pydantic field on through model that leads to passed model and is registered as field_name passed.
Through model is fetched from through attributed on passed model_field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field_name |
str
|
field name to register |
required |
model |
Type[Model]
|
type of field to register |
required |
model_field |
ManyToManyField
|
relation field from which through model is extracted |
required |
Source code in ormar\models\helpers\pydantic.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
get_potential_fields(attrs)
Gets all the fields in current class namespace that are Fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attrs |
Union[Dict, MappingProxyType]
|
current class namespace |
required |
Returns:
Type | Description |
---|---|
Dict
|
extracted fields that are ormar Fields |
Source code in ormar\models\helpers\pydantic.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
get_pydantic_base_orm_config()
Returns empty pydantic Config with orm_mode set to True.
Returns:
Type | Description |
---|---|
pydantic Config
|
empty default config with orm_mode set. |
Source code in ormar\models\helpers\pydantic.py
126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_pydantic_field(field_name, model)
Extracts field type and if it's required from Model model_fields by passed field_name. Returns a pydantic field with type of field_name field type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field_name |
str
|
field name to fetch from Model and name of pydantic field |
required |
model |
Type[Model]
|
type of field to register |
required |
Returns:
Type | Description |
---|---|
pydantic.ModelField
|
newly created pydantic field |
Source code in ormar\models\helpers\pydantic.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
merge_or_generate_pydantic_config(attrs, name)
Checks if the user provided pydantic Config, and if he did merges it with the default one.
Updates the attrs in place with a new config.
Source code in ormar\models\helpers\pydantic.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
populate_pydantic_default_values(attrs)
Extracts ormar fields from annotations (deprecated) and from namespace dictionary of the class. Fields declared on model are all subclasses of the BaseField class.
Trigger conversion of ormar field into pydantic FieldInfo, which has all needed parameters saved.
Overwrites the annotations of ormar fields to corresponding types declared on ormar fields (constructed dynamically for relations). Those annotations are later used by pydantic to construct it's own fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attrs |
Dict
|
current class namespace |
required |
Returns:
Type | Description |
---|---|
Tuple[Dict, Dict]
|
namespace of the class updated, dict of extracted model_fields |
Source code in ormar\models\helpers\pydantic.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
remove_excluded_parent_fields(model)
Removes pydantic fields that should be excluded from parent models
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Type[Model]
|
|
required |
Source code in ormar\models\helpers\pydantic.py
157 158 159 160 161 162 163 164 165 166 167 168 |
|