mixins
Package contains functionalities divided by features. All mixins are combined into ModelTableProxy which is one of the parents of Model. The split into mixins was done to ease the maintainability of the proxy class, as it became quite complicated over time.
AliasMixin
Used to translate field names into database column names.
Source code in ormar\models\mixins\alias_mixin.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
get_column_alias(field_name)
classmethod
Returns db alias (column name in db) for given ormar field. For fields without alias field name is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field_name |
str
|
name of the field to get alias from |
required |
Returns:
Type | Description |
---|---|
str
|
alias (db name) if set, otherwise passed name |
Source code in ormar\models\mixins\alias_mixin.py
14 15 16 17 18 19 20 21 22 23 24 25 |
|
get_column_name_from_alias(alias)
classmethod
Returns ormar field name for given db alias (column name in db). If field do not have alias it's returned as is.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alias |
str
|
|
required |
Returns:
Type | Description |
---|---|
str
|
field name if set, otherwise passed alias (db name) |
Source code in ormar\models\mixins\alias_mixin.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
translate_aliases_to_columns(new_kwargs)
classmethod
Translates dictionary of model fields changing aliases into field names. If field has no alias the alias is already a field name. Only fields present in the dictionary are translated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_kwargs |
Dict
|
dict with aliases and their values |
required |
Returns:
Type | Description |
---|---|
Dict
|
dict with fields names and their values |
Source code in ormar\models\mixins\alias_mixin.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
translate_columns_to_aliases(new_kwargs)
classmethod
Translates dictionary of model fields changing field names into aliases. If field has no alias the field name remains intact. Only fields present in the dictionary are translated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_kwargs |
Dict
|
dict with fields names and their values |
required |
Returns:
Type | Description |
---|---|
Dict
|
dict with aliases and their values |
Source code in ormar\models\mixins\alias_mixin.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
ExcludableMixin
Bases: RelationMixin
Used to include/exclude given set of fields on models during load and dict() calls.
Source code in ormar\models\mixins\excludable_mixin.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
Model
Bases: ModelRow
Source code in ormar\models\model.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
delete()
async
Removes the Model instance from the database.
Sends pre_delete and post_delete signals.
Sets model save status to False.
Note it does not delete the Model itself (python object). So you can delete and later save (since pk is deleted no conflict will arise) or update and the Model will be saved in database again.
Returns:
Type | Description |
---|---|
int
|
number of deleted rows (for some backends) |
Source code in ormar\models\model.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
load()
async
Allow to refresh existing Models fields from database. Be careful as the related models can be overwritten by pk_only models in load. Does NOT refresh the related models fields if they were loaded before.
Returns:
Type | Description |
---|---|
Model
|
reloaded Model |
Raises:
Type | Description |
---|---|
NoMatch
|
If given pk is not found in database. |
Source code in ormar\models\model.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
load_all(follow=False, exclude=None, order_by=None)
async
Allow to refresh existing Models fields from database. Performs refresh of the related models fields.
By default, loads only self and the directly related ones.
If follow=True is set it loads also related models of related models.
To not get stuck in an infinite loop as related models also keep a relation to parent model visited models set is kept.
That way already visited models that are nested are loaded, but the load do not follow them inside. So Model A -> Model B -> Model C -> Model A -> Model X will load second Model A but will never follow into Model X. Nested relations of those kind need to be loaded manually.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
order_by |
Union[List, str, None]
|
columns by which models should be sorted |
None
|
exclude |
Union[List, str, Set, Dict, None]
|
related models to exclude |
None
|
follow |
bool
|
flag to trigger deep save - by default only directly related models are saved with follow=True also related models of related models are saved |
False
|
Returns:
Type | Description |
---|---|
Model
|
reloaded Model |
Raises:
Type | Description |
---|---|
NoMatch
|
If given pk is not found in database. |
Source code in ormar\models\model.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
save()
async
Performs a save of given Model instance. If primary key is already saved, db backend will throw integrity error.
Related models are saved by pk number, reverse relation and many to many fields are not saved - use corresponding relations methods.
If there are fields with server_default set and those fields are not already filled save will trigger also a second query to refreshed the fields populated server side.
Does not recognize if model was previously saved. If you want to perform update or insert depending on the pk fields presence use upsert.
Sends pre_save and post_save signals.
Sets model save status to True.
Returns:
Type | Description |
---|---|
Model
|
saved Model |
Source code in ormar\models\model.py
53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
save_related(follow=False, save_all=False, relation_map=None, exclude=None, update_count=0, previous_model=None, relation_field=None)
async
Triggers a upsert method on all related models if the instances are not already saved. By default saves only the directly related ones.
If follow=True is set it saves also related models of related models.
To not get stuck in an infinite loop as related models also keep a relation to parent model visited models set is kept.
That way already visited models that are nested are saved, but the save do not follow them inside. So Model A -> Model B -> Model A -> Model C will save second Model A but will never follow into Model C. Nested relations of those kind need to be persisted manually.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relation_field |
Optional[ForeignKeyField]
|
field with relation leading to this model |
None
|
previous_model |
Optional[Model]
|
previous model from which method came |
None
|
exclude |
Union[Set, Dict, None]
|
items to exclude during saving of relations |
None
|
relation_map |
Optional[Dict]
|
map of relations to follow |
None
|
save_all |
bool
|
flag if all models should be saved or only not saved ones |
False
|
follow |
bool
|
flag to trigger deep save - by default only directly related models are saved with follow=True also related models of related models are saved |
False
|
update_count |
int
|
internal parameter for recursive calls - number of updated instances |
0
|
Returns:
Type | Description |
---|---|
int
|
number of updated/saved models |
Source code in ormar\models\model.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
update(_columns=None, **kwargs)
async
Performs update of Model instance in the database. Fields can be updated before or you can pass them as kwargs.
Sends pre_update and post_update signals.
Sets model save status to True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_columns |
Optional[List[str]]
|
list of columns to update, if None all are updated |
None
|
kwargs |
Any
|
list of fields to update as field=value pairs |
{}
|
Returns:
Type | Description |
---|---|
Model
|
updated Model |
Raises:
Type | Description |
---|---|
ModelPersistenceError
|
If the pk column is not set |
Source code in ormar\models\model.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
upsert(**kwargs)
async
Performs either a save or an update depending on the presence of the pk. If the pk field is filled it's an update, otherwise the save is performed. For save kwargs are ignored, used only in update if provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs |
Any
|
list of fields to update |
{}
|
Returns:
Type | Description |
---|---|
Model
|
saved Model |
Source code in ormar\models\model.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
ModelRow
Bases: NewBaseModel
Source code in ormar\models\model_row.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
extract_prefixed_table_columns(item, row, table_prefix, excludable)
classmethod
Extracts own fields from raw sql result, using a given prefix. Prefix changes depending on the table's position in a join.
If the table is a main table, there is no prefix. All joined tables have prefixes to allow duplicate column names, as well as duplicated joins to the same table from multiple different tables.
Extracted fields populates the related dict later used to construct a Model.
Used in Model.from_row and PrefetchQuery._populate_rows methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
excludable |
ExcludableItems
|
structure of fields to include and exclude |
required |
item |
dict
|
dictionary of already populated nested models, otherwise empty dict |
required |
row |
Row
|
raw result row from the database |
required |
table_prefix |
str
|
prefix of the table from AliasManager each pair of tables have own prefix (two of them depending on direction) - used in joins to allow multiple joins to the same table. |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary with keys corresponding to model fields names and values are database values |
Source code in ormar\models\model_row.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
from_row(row, source_model, select_related=None, related_models=None, related_field=None, excludable=None, current_relation_str='', proxy_source_model=None, used_prefixes=None)
classmethod
Model method to convert raw sql row from database into ormar.Model instance. Traverses nested models if they were specified in select_related for query.
Called recurrently and returns model instance if it's present in the row. Note that it's processing one row at a time, so if there are duplicates of parent row that needs to be joined/combined (like parent row in sql join with 2+ child rows) instances populated in this method are later combined in the QuerySet. Other method working directly on raw database results is in prefetch_query, where rows are populated in a different way as they do not have nested models in result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
used_prefixes |
Optional[List[str]]
|
list of already extracted prefixes |
None
|
proxy_source_model |
Optional[Type[Model]]
|
source model from which querysetproxy is constructed |
None
|
excludable |
Optional[ExcludableItems]
|
structure of fields to include and exclude |
None
|
current_relation_str |
str
|
name of the relation field |
''
|
source_model |
Type[Model]
|
model on which relation was defined |
required |
row |
Row
|
raw result row from the database |
required |
select_related |
Optional[List]
|
list of names of related models fetched from database |
None
|
related_models |
Any
|
list or dict of related models |
None
|
related_field |
Optional[ForeignKeyField]
|
field with relation declaration |
None
|
Returns:
Type | Description |
---|---|
Optional[Model]
|
returns model if model is populated from database |
Source code in ormar\models\model_row.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 |
|
get_child(items, key=None)
staticmethod
Used to get nested dictionaries keys if they exists otherwise returns passed items.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
items |
Union[Set, Dict, None]
|
bag of items to include or exclude |
required |
key |
Optional[str]
|
name of the child to extract |
None
|
Returns:
Type | Description |
---|---|
Union[Set, Dict, None]
|
child extracted from items if exists |
Source code in ormar\models\mixins\excludable_mixin.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
get_names_to_exclude(excludable, alias)
classmethod
Returns a set of models field names that should be explicitly excluded during model initialization.
Those fields will be set to None to avoid ormar/pydantic setting default values on them. They should be returned as None in any case.
Used in parsing data from database rows that construct Models by initializing them with dicts constructed from those db rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alias |
str
|
alias of current relation |
required |
excludable |
ExcludableItems
|
structure of fields to include and exclude |
required |
Returns:
Type | Description |
---|---|
Set
|
set of field names that should be excluded |
Source code in ormar\models\mixins\excludable_mixin.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
own_table_columns(model, excludable, alias='', use_alias=False, add_pk_columns=True)
classmethod
Returns list of aliases or field names for given model. Aliases/names switch is use_alias flag.
If provided only fields included in fields will be returned. If provided fields in exclude_fields will be excluded in return.
Primary key field is always added and cannot be excluded (will be added anyway).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
add_pk_columns |
bool
|
flag if add primary key - always yes if ormar parses data |
True
|
alias |
str
|
relation prefix |
''
|
excludable |
ExcludableItems
|
structure of fields to include and exclude |
required |
model |
Union[Type[Model], Type[ModelRow]]
|
model on columns are selected |
required |
use_alias |
bool
|
flag if aliases or field names should be used |
False
|
Returns:
Type | Description |
---|---|
List[str]
|
list of column field names or aliases |
Source code in ormar\models\mixins\excludable_mixin.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
MergeModelMixin
Used to merge models instances returned by database, but already initialized to ormar Models.keys
Models can duplicate during joins when parent model has multiple child rows, in the end all parent (main) models should be unique.
Source code in ormar\models\mixins\merge_mixin.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
merge_instances_list(result_rows)
classmethod
Merges a list of models into list of unique models.
Models can duplicate during joins when parent model has multiple child rows, in the end all parent (main) models should be unique.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result_rows |
List[Model]
|
list of already initialized Models with child models populated, each instance is one row in db and some models can duplicate |
required |
Returns:
Type | Description |
---|---|
List["Model"]
|
list of merged models where each main model is unique |
Source code in ormar\models\mixins\merge_mixin.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
merge_two_instances(one, other, relation_map=None)
classmethod
Merges current (other) Model and previous one (one) and returns the current Model instance with data merged from previous one.
If needed it's calling itself recurrently and merges also children models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
relation_map |
Optional[Dict]
|
map of models relations to follow |
None
|
one |
Model
|
previous model instance |
required |
other |
Model
|
current model instance |
required |
Returns:
Type | Description |
---|---|
Model
|
current Model instance with data merged from previous one. |
Source code in ormar\models\mixins\merge_mixin.py
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
PydanticMixin
Bases: RelationMixin
Source code in ormar\models\mixins\pydantic_mixin.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
copy_selected_validators_type(model, fields, validator_type)
classmethod
Copy field validators from ormar model to generated pydantic model.
Source code in ormar\models\mixins\pydantic_mixin.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
get_pydantic(*, include=None, exclude=None)
classmethod
Returns a pydantic model out of ormar model.
Converts also nested ormar models into pydantic models.
Can be used to fully exclude certain fields in fastapi response and requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include |
Union[Set, Dict, None]
|
fields of own and nested models to include |
None
|
exclude |
Union[Set, Dict, None]
|
fields of own and nested models to exclude |
None
|
Source code in ormar\models\mixins\pydantic_mixin.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
SavePrepareMixin
Bases: RelationMixin
, AliasMixin
Used to prepare models to be saved in database
Source code in ormar\models\mixins\save_mixin.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
dump_all_json_fields_to_str(model_dict)
classmethod
Receives dictionary of model that is about to be saved and changes all json fields into strings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_dict |
Dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
parse_non_db_fields(model_dict)
classmethod
Receives dictionary of model that is about to be saved and changes uuid fields to strings in bulk_update.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_dict |
Dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
populate_default_values(new_kwargs)
classmethod
Receives dictionary of model that is about to be saved and populates the default value on the fields that have the default value set, but no actual value was passed by the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_kwargs |
Dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
prepare_model_to_save(new_kwargs)
classmethod
Combines all preparation methods before saving. Removes primary key for if it's nullable or autoincrement pk field, and it's set to None. Substitute related models with their primary key values as fk column. Populates the default values for field with default set and no value. Translate columns into aliases (db names).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_kwargs |
dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
prepare_model_to_update(new_kwargs)
classmethod
Combines all preparation methods before updating.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_kwargs |
dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
dictionary of model that is about to be updated |
Source code in ormar\models\mixins\save_mixin.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
reconvert_str_to_bytes(model_dict)
classmethod
Receives dictionary of model that is about to be saved and changes all bytes fields that are represented as strings back into bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_dict |
Dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
substitute_models_with_pks(model_dict)
classmethod
Receives dictionary of model that is about to be saved and changes all related models that are stored as foreign keys to their fk value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_dict |
Dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
validate_enums(new_kwargs)
classmethod
Receives dictionary of model that is about to be saved and validates the fields with choices set to see if the value is allowed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_kwargs |
Dict
|
dictionary of model that is about to be saved |
required |
Returns:
Type | Description |
---|---|
Dict
|
dictionary of model that is about to be saved |
Source code in ormar\models\mixins\save_mixin.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|