update docs, add load_all(), tests for load_all, make through field optional
This commit is contained in:
@ -30,88 +30,12 @@ passed items.
|
||||
|
||||
`(Union[Set, Dict, None])`: child extracted from items if exists
|
||||
|
||||
<a name="models.mixins.excludable_mixin.ExcludableMixin.get_excluded"></a>
|
||||
#### get\_excluded
|
||||
|
||||
```python
|
||||
| @staticmethod
|
||||
| get_excluded(exclude: Union[Set, Dict, None], key: str = None) -> Union[Set, Dict, None]
|
||||
```
|
||||
|
||||
Proxy to ExcludableMixin.get_child for exclusions.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `exclude (Union[Set, Dict, None])`: bag of items to exclude
|
||||
- `key (str)`: name of the child to extract
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Union[Set, Dict, None])`: child extracted from items if exists
|
||||
|
||||
<a name="models.mixins.excludable_mixin.ExcludableMixin.get_included"></a>
|
||||
#### get\_included
|
||||
|
||||
```python
|
||||
| @staticmethod
|
||||
| get_included(include: Union[Set, Dict, None], key: str = None) -> Union[Set, Dict, None]
|
||||
```
|
||||
|
||||
Proxy to ExcludableMixin.get_child for inclusions.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `include (Union[Set, Dict, None])`: bag of items to include
|
||||
- `key (str)`: name of the child to extract
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Union[Set, Dict, None])`: child extracted from items if exists
|
||||
|
||||
<a name="models.mixins.excludable_mixin.ExcludableMixin.is_excluded"></a>
|
||||
#### is\_excluded
|
||||
|
||||
```python
|
||||
| @staticmethod
|
||||
| is_excluded(exclude: Union[Set, Dict, None], key: str = None) -> bool
|
||||
```
|
||||
|
||||
Checks if given key should be excluded on model/ dict.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `exclude (Union[Set, Dict, None])`: bag of items to exclude
|
||||
- `key (str)`: name of the child to extract
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Union[Set, Dict, None])`: child extracted from items if exists
|
||||
|
||||
<a name="models.mixins.excludable_mixin.ExcludableMixin.is_included"></a>
|
||||
#### is\_included
|
||||
|
||||
```python
|
||||
| @staticmethod
|
||||
| is_included(include: Union[Set, Dict, None], key: str = None) -> bool
|
||||
```
|
||||
|
||||
Checks if given key should be included on model/ dict.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `include (Union[Set, Dict, None])`: bag of items to include
|
||||
- `key (str)`: name of the child to extract
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Union[Set, Dict, None])`: child extracted from items if exists
|
||||
|
||||
<a name="models.mixins.excludable_mixin.ExcludableMixin._populate_pk_column"></a>
|
||||
#### \_populate\_pk\_column
|
||||
|
||||
```python
|
||||
| @staticmethod
|
||||
| _populate_pk_column(model: Type["Model"], columns: List[str], use_alias: bool = False) -> List[str]
|
||||
| _populate_pk_column(model: Union[Type["Model"], Type["ModelRow"]], columns: List[str], use_alias: bool = False) -> List[str]
|
||||
```
|
||||
|
||||
Adds primary key column/alias (depends on use_alias flag) to list of
|
||||
@ -132,7 +56,7 @@ column names that are selected.
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| own_table_columns(cls, model: Type["Model"], fields: Optional[Union[Set, Dict]], exclude_fields: Optional[Union[Set, Dict]], use_alias: bool = False) -> List[str]
|
||||
| own_table_columns(cls, model: Union[Type["Model"], Type["ModelRow"]], excludable: ExcludableItems, alias: str = "", use_alias: bool = False) -> List[str]
|
||||
```
|
||||
|
||||
Returns list of aliases or field names for given model.
|
||||
@ -145,9 +69,9 @@ Primary key field is always added and cannot be excluded (will be added anyway).
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `alias (str)`: relation prefix
|
||||
- `excludable (ExcludableItems)`: structure of fields to include and exclude
|
||||
- `model (Type["Model"])`: model on columns are selected
|
||||
- `fields (Optional[Union[Set, Dict]])`: set/dict of fields to include
|
||||
- `exclude_fields (Optional[Union[Set, Dict]])`: set/dict of fields to exclude
|
||||
- `use_alias (bool)`: flag if aliases or field names should be used
|
||||
|
||||
**Returns**:
|
||||
@ -183,7 +107,7 @@ exclusion, for nested models all related models are excluded.
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_names_to_exclude(cls, fields: Optional[Union[Dict, Set]] = None, exclude_fields: Optional[Union[Dict, Set]] = None) -> Set
|
||||
| get_names_to_exclude(cls, excludable: ExcludableItems, alias: str) -> Set
|
||||
```
|
||||
|
||||
Returns a set of models field names that should be explicitly excluded
|
||||
@ -197,8 +121,8 @@ them with dicts constructed from those db rows.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `fields (Optional[Union[Set, Dict]])`: set/dict of fields to include
|
||||
- `exclude_fields (Optional[Union[Set, Dict]])`: set/dict of fields to exclude
|
||||
- `alias (str)`: alias of current relation
|
||||
- `excludable (ExcludableItems)`: structure of fields to include and exclude
|
||||
|
||||
**Returns**:
|
||||
|
||||
|
||||
@ -40,12 +40,26 @@ List is cached in cls._related_fields for quicker access.
|
||||
|
||||
`(List)`: list of related fields
|
||||
|
||||
<a name="models.mixins.relation_mixin.RelationMixin.extract_through_names"></a>
|
||||
#### extract\_through\_names
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| extract_through_names(cls) -> Set
|
||||
```
|
||||
|
||||
Extracts related fields through names which are shortcuts to through models.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Set)`: set of related through fields names
|
||||
|
||||
<a name="models.mixins.relation_mixin.RelationMixin.extract_related_names"></a>
|
||||
#### extract\_related\_names
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| extract_related_names(cls) -> Set
|
||||
| extract_related_names(cls) -> Set[str]
|
||||
```
|
||||
|
||||
Returns List of fields names for all relations declared on a model.
|
||||
@ -53,7 +67,7 @@ List is cached in cls._related_names for quicker access.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(List)`: list of related fields names
|
||||
`(Set)`: set of related fields names
|
||||
|
||||
<a name="models.mixins.relation_mixin.RelationMixin._extract_db_related_names"></a>
|
||||
#### \_extract\_db\_related\_names
|
||||
@ -91,3 +105,24 @@ for nested models all related models are returned.
|
||||
|
||||
`(Set)`: set of non mandatory related fields
|
||||
|
||||
<a name="models.mixins.relation_mixin.RelationMixin._iterate_related_models"></a>
|
||||
#### \_iterate\_related\_models
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| _iterate_related_models(cls, visited: Set[Union[Type["Model"], Type["RelationMixin"]]] = None, source_relation: str = None, source_model: Union[Type["Model"], Type["RelationMixin"]] = None) -> List[str]
|
||||
```
|
||||
|
||||
Iterates related models recursively to extract relation strings of
|
||||
nested not visited models.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `visited (Set[str])`: set of already visited models
|
||||
- `source_relation (str)`: name of the current relation
|
||||
- `source_model (Type["Model"])`: model from which relation comes in nested relations
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(List[str])`: list of relation strings to be passed to select_related
|
||||
|
||||
|
||||
@ -91,3 +91,22 @@ passed by the user.
|
||||
|
||||
`(Dict)`: dictionary of model that is about to be saved
|
||||
|
||||
<a name="models.mixins.save_mixin.SavePrepareMixin.validate_choices"></a>
|
||||
#### validate\_choices
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| validate_choices(cls, new_kwargs: Dict) -> Dict
|
||||
```
|
||||
|
||||
Receives dictionary of model that is about to be saved and validates the
|
||||
fields with choices set to see if the value is allowed.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `new_kwargs (Dict)`: dictionary of model that is about to be saved
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Dict)`: dictionary of model that is about to be saved
|
||||
|
||||
|
||||
Reference in New Issue
Block a user