fix isnull typo and formatting

This commit is contained in:
collerek
2021-04-22 18:55:45 +02:00
parent 0fcdcbdf1d
commit 2088cb16b5
38 changed files with 1784 additions and 458 deletions

View File

@ -5,7 +5,7 @@
#### is\_field\_an\_forward\_ref
```python
is_field_an_forward_ref(field: Type["BaseField"]) -> bool
is_field_an_forward_ref(field: "BaseField") -> bool
```
Checks if field is a relation field and whether any of the referenced models
@ -91,7 +91,7 @@ extraction of ormar model_fields.
#### group\_related\_list
```python
group_related_list(list_: List) -> Dict
group_related_list(list_: List) -> collections.OrderedDict
```
Translates the list of related strings into a dictionary.

View File

@ -5,7 +5,7 @@
#### create\_pydantic\_field
```python
create_pydantic_field(field_name: str, model: Type["Model"], model_field: Type["ManyToManyField"]) -> None
create_pydantic_field(field_name: str, model: Type["Model"], model_field: "ManyToManyField") -> None
```
Registers pydantic field on through model that leads to passed model
@ -38,32 +38,6 @@ field_name. Returns a pydantic field with type of field_name field type.
`(pydantic.ModelField)`: newly created pydantic field
<a name="models.helpers.pydantic.populate_default_pydantic_field_value"></a>
#### populate\_default\_pydantic\_field\_value
```python
populate_default_pydantic_field_value(ormar_field: Type["BaseField"], field_name: str, attrs: dict) -> dict
```
Grabs current value of the ormar Field in class namespace
(so the default_value declared on ormar model if set)
and converts it to pydantic.FieldInfo
that pydantic is able to extract later.
On FieldInfo there are saved all needed params like max_length of the string
and other constraints that pydantic can use to build
it's own field validation used by ormar.
**Arguments**:
- `ormar_field (ormar Field)`: field to convert
- `field_name (str)`: field to convert name
- `attrs (Dict)`: current class namespace
**Returns**:
`(Dict)`: updated namespace dict
<a name="models.helpers.pydantic.populate_pydantic_default_values"></a>
#### populate\_pydantic\_default\_values
@ -76,7 +50,7 @@ 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
paramaters saved.
parameters saved.
Overwrites the annotations of ormar fields to corresponding types declared on
ormar fields (constructed dynamically for relations).

View File

@ -5,7 +5,7 @@
#### register\_relation\_on\_build
```python
register_relation_on_build(field: Type["ForeignKeyField"]) -> None
register_relation_on_build(field: "ForeignKeyField") -> None
```
Registers ForeignKey relation in alias_manager to set a table_prefix.
@ -23,7 +23,7 @@ aliases for proper sql joins.
#### register\_many\_to\_many\_relation\_on\_build
```python
register_many_to_many_relation_on_build(field: Type["ManyToManyField"]) -> None
register_many_to_many_relation_on_build(field: "ManyToManyField") -> None
```
Registers connection between through model and both sides of the m2m relation.
@ -43,7 +43,7 @@ By default relation name is a model.name.lower().
#### expand\_reverse\_relationship
```python
expand_reverse_relationship(model_field: Type["ForeignKeyField"]) -> None
expand_reverse_relationship(model_field: "ForeignKeyField") -> None
```
If the reverse relation has not been set before it's set here.
@ -76,7 +76,7 @@ If the reverse relation has not been set before it's set here.
#### register\_reverse\_model\_fields
```python
register_reverse_model_fields(model_field: Type["ForeignKeyField"]) -> None
register_reverse_model_fields(model_field: "ForeignKeyField") -> None
```
Registers reverse ForeignKey field on related model.
@ -93,7 +93,7 @@ Autogenerated reverse fields also set related_name to the original field name.
#### register\_through\_shortcut\_fields
```python
register_through_shortcut_fields(model_field: Type["ManyToManyField"]) -> None
register_through_shortcut_fields(model_field: "ManyToManyField") -> None
```
Registers m2m relation through shortcut on both ends of the relation.
@ -106,7 +106,7 @@ Registers m2m relation through shortcut on both ends of the relation.
#### register\_relation\_in\_alias\_manager
```python
register_relation_in_alias_manager(field: Type["ForeignKeyField"]) -> None
register_relation_in_alias_manager(field: "ForeignKeyField") -> None
```
Registers the relation (and reverse relation) in alias manager.
@ -125,7 +125,7 @@ fk - register_relation_on_build
#### verify\_related\_name\_dont\_duplicate
```python
verify_related_name_dont_duplicate(related_name: str, model_field: Type["ForeignKeyField"]) -> None
verify_related_name_dont_duplicate(related_name: str, model_field: "ForeignKeyField") -> None
```
Verifies whether the used related_name (regardless of the fact if user defined or
@ -150,7 +150,7 @@ model
#### reverse\_field\_not\_already\_registered
```python
reverse_field_not_already_registered(model_field: Type["ForeignKeyField"]) -> bool
reverse_field_not_already_registered(model_field: "ForeignKeyField") -> bool
```
Checks if child is already registered in parents pydantic fields.

View File

@ -5,7 +5,7 @@
#### adjust\_through\_many\_to\_many\_model
```python
adjust_through_many_to_many_model(model_field: Type["ManyToManyField"]) -> None
adjust_through_many_to_many_model(model_field: "ManyToManyField") -> None
```
Registers m2m relation on through model.
@ -21,7 +21,7 @@ Sets pydantic fields with child and parent model types.
#### create\_and\_append\_m2m\_fk
```python
create_and_append_m2m_fk(model: Type["Model"], model_field: Type["ManyToManyField"], field_name: str) -> None
create_and_append_m2m_fk(model: Type["Model"], model_field: "ManyToManyField", field_name: str) -> None
```
Registers sqlalchemy Column with sqlalchemy.ForeignKey leading to the model.
@ -98,6 +98,72 @@ or pkname validation fails.
`(Tuple[Optional[str], List[sqlalchemy.Column]])`: pkname, list of sqlalchemy columns
<a name="models.helpers.sqlalchemy._process_fields"></a>
#### \_process\_fields
```python
_process_fields(model_fields: Dict, new_model: Type["Model"]) -> Tuple[Optional[str], List[sqlalchemy.Column]]
```
Helper method.
Populates pkname and columns.
Trigger validation of primary_key - only one and required pk can be set,
cannot be pydantic_only.
Append fields to columns if it's not pydantic_only,
virtual ForeignKey or ManyToMany field.
Sets `owner` on each model_field as reference to newly created Model.
**Raises**:
- `ModelDefinitionError`: if validation of related_names fail,
or pkname validation fails.
**Arguments**:
- `model_fields (Dict[str, ormar.Field])`: dictionary of declared ormar model fields
- `new_model (Model class)`:
**Returns**:
`(Tuple[Optional[str], List[sqlalchemy.Column]])`: pkname, list of sqlalchemy columns
<a name="models.helpers.sqlalchemy._is_through_model_not_set"></a>
#### \_is\_through\_model\_not\_set
```python
_is_through_model_not_set(field: "BaseField") -> bool
```
Alias to if check that verifies if through model was created.
**Arguments**:
- `field ("BaseField")`: field to check
**Returns**:
`(bool)`: result of the check
<a name="models.helpers.sqlalchemy._is_db_field"></a>
#### \_is\_db\_field
```python
_is_db_field(field: "BaseField") -> bool
```
Alias to if check that verifies if field should be included in database.
**Arguments**:
- `field ("BaseField")`: field to check
**Returns**:
`(bool)`: result of the check
<a name="models.helpers.sqlalchemy.populate_meta_tablename_columns_and_pk"></a>
#### populate\_meta\_tablename\_columns\_and\_pk
@ -165,7 +231,7 @@ It populates name, metadata, columns and constraints.
#### update\_column\_definition
```python
update_column_definition(model: Union[Type["Model"], Type["NewBaseModel"]], field: Type["ForeignKeyField"]) -> None
update_column_definition(model: Union[Type["Model"], Type["NewBaseModel"]], field: "ForeignKeyField") -> None
```
Updates a column with a new type column based on updated parameters in FK fields.
@ -173,7 +239,7 @@ Updates a column with a new type column based on updated parameters in FK fields
**Arguments**:
- `model (Type["Model"])`: model on which columns needs to be updated
- `field (Type[ForeignKeyField])`: field with column definition that requires update
- `field (ForeignKeyField)`: field with column definition that requires update
**Returns**:

View File

@ -5,7 +5,7 @@
#### check\_if\_field\_has\_choices
```python
check_if_field_has_choices(field: Type[BaseField]) -> bool
check_if_field_has_choices(field: BaseField) -> bool
```
Checks if given field has choices populated.
@ -23,7 +23,7 @@ A if it has one, a validator for this field needs to be attached.
#### convert\_choices\_if\_needed
```python
convert_choices_if_needed(field: Type["BaseField"], value: Any) -> Tuple[Any, List]
convert_choices_if_needed(field: "BaseField", value: Any) -> Tuple[Any, List]
```
Converts dates to isoformat as fastapi can check this condition in routes
@ -37,7 +37,7 @@ Converts decimal to float with given scale.
**Arguments**:
- `field (Type[BaseField])`: ormar field to check with choices
- `field (BaseField)`: ormar field to check with choices
- `values (Dict)`: current values of the model to verify
**Returns**:
@ -48,7 +48,7 @@ Converts decimal to float with given scale.
#### validate\_choices
```python
validate_choices(field: Type["BaseField"], value: Any) -> None
validate_choices(field: "BaseField", value: Any) -> None
```
Validates if given value is in provided choices.
@ -59,7 +59,7 @@ Validates if given value is in provided choices.
**Arguments**:
- `field (Type[BaseField])`: field to validate
- `field (BaseField)`: field to validate
- `value (Any)`: value of the field
<a name="models.helpers.validation.choices_validator"></a>