next part of the docs and api documentation in beta ver
This commit is contained in:
292
docs/api/fields/base-field.md
Normal file
292
docs/api/fields/base-field.md
Normal file
@ -0,0 +1,292 @@
|
||||
<a name="fields.base"></a>
|
||||
# fields.base
|
||||
|
||||
<a name="fields.base.BaseField"></a>
|
||||
## BaseField Objects
|
||||
|
||||
```python
|
||||
class BaseField(FieldInfo)
|
||||
```
|
||||
|
||||
BaseField serves as a parent class for all basic Fields in ormar.
|
||||
It keeps all common parameters available for all fields as well as
|
||||
set of useful functions.
|
||||
|
||||
All values are kept as class variables, ormar Fields are never instantiated.
|
||||
Subclasses pydantic.FieldInfo to keep the fields related
|
||||
to pydantic field types like ConstrainedStr
|
||||
|
||||
<a name="fields.base.BaseField.__type__"></a>
|
||||
#### \_\_type\_\_
|
||||
|
||||
<a name="fields.base.BaseField.related_name"></a>
|
||||
#### related\_name
|
||||
|
||||
<a name="fields.base.BaseField.column_type"></a>
|
||||
#### column\_type
|
||||
|
||||
<a name="fields.base.BaseField.constraints"></a>
|
||||
#### constraints
|
||||
|
||||
<a name="fields.base.BaseField.name"></a>
|
||||
#### name
|
||||
|
||||
<a name="fields.base.BaseField.alias"></a>
|
||||
#### alias
|
||||
|
||||
<a name="fields.base.BaseField.primary_key"></a>
|
||||
#### primary\_key
|
||||
|
||||
<a name="fields.base.BaseField.autoincrement"></a>
|
||||
#### autoincrement
|
||||
|
||||
<a name="fields.base.BaseField.nullable"></a>
|
||||
#### nullable
|
||||
|
||||
<a name="fields.base.BaseField.index"></a>
|
||||
#### index
|
||||
|
||||
<a name="fields.base.BaseField.unique"></a>
|
||||
#### unique
|
||||
|
||||
<a name="fields.base.BaseField.pydantic_only"></a>
|
||||
#### pydantic\_only
|
||||
|
||||
<a name="fields.base.BaseField.virtual"></a>
|
||||
#### virtual
|
||||
|
||||
<a name="fields.base.BaseField.choices"></a>
|
||||
#### choices
|
||||
|
||||
<a name="fields.base.BaseField.to"></a>
|
||||
#### to
|
||||
|
||||
<a name="fields.base.BaseField.through"></a>
|
||||
#### through
|
||||
|
||||
<a name="fields.base.BaseField.default"></a>
|
||||
#### default
|
||||
|
||||
<a name="fields.base.BaseField.server_default"></a>
|
||||
#### server\_default
|
||||
|
||||
<a name="fields.base.BaseField.is_valid_uni_relation"></a>
|
||||
#### is\_valid\_uni\_relation
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| is_valid_uni_relation(cls) -> bool
|
||||
```
|
||||
|
||||
Checks if field is a relation definition but only for ForeignKey relation,
|
||||
so excludes ManyToMany fields, as well as virtual ForeignKey
|
||||
(second side of FK relation).
|
||||
|
||||
Is used to define if a field is a db ForeignKey column that
|
||||
should be saved/populated when dealing with internal/own
|
||||
Model columns only.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: result of the check
|
||||
|
||||
<a name="fields.base.BaseField.get_alias"></a>
|
||||
#### get\_alias
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_alias(cls) -> str
|
||||
```
|
||||
|
||||
Used to translate Model column names to database column names during db queries.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(str)`: returns custom database column name if defined by user,
|
||||
otherwise field name in ormar/pydantic
|
||||
|
||||
<a name="fields.base.BaseField.is_valid_field_info_field"></a>
|
||||
#### is\_valid\_field\_info\_field
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| is_valid_field_info_field(cls, field_name: str) -> bool
|
||||
```
|
||||
|
||||
Checks if field belongs to pydantic FieldInfo
|
||||
- used during setting default pydantic values.
|
||||
Excludes defaults and alias as they are populated separately
|
||||
(defaults) or not at all (alias)
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `field_name (str)`: field name of BaseFIeld
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: True if field is present on pydantic.FieldInfo
|
||||
|
||||
<a name="fields.base.BaseField.convert_to_pydantic_field_info"></a>
|
||||
#### convert\_to\_pydantic\_field\_info
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| convert_to_pydantic_field_info(cls, allow_null: bool = False) -> FieldInfo
|
||||
```
|
||||
|
||||
Converts a BaseField into pydantic.FieldInfo
|
||||
that is later easily processed by pydantic.
|
||||
Used in an ormar Model Metaclass.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `allow_null (bool)`: flag if the default value can be None
|
||||
or if it should be populated by pydantic Undefined
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(pydantic.FieldInfo)`: actual instance of pydantic.FieldInfo with all needed fields populated
|
||||
|
||||
<a name="fields.base.BaseField.default_value"></a>
|
||||
#### default\_value
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| default_value(cls, use_server: bool = False) -> Optional[FieldInfo]
|
||||
```
|
||||
|
||||
Returns a FieldInfo instance with populated default
|
||||
(static) or default_factory (function).
|
||||
If the field is a autoincrement primary key the default is None.
|
||||
Otherwise field have to has either default, or default_factory populated.
|
||||
|
||||
If all default conditions fail None is returned.
|
||||
|
||||
Used in converting to pydantic FieldInfo.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `use_server (bool)`: flag marking if server_default should be
|
||||
treated as default value, default False
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Optional[pydantic.FieldInfo])`: returns a call to pydantic.Field
|
||||
which is returning a FieldInfo instance
|
||||
|
||||
<a name="fields.base.BaseField.get_default"></a>
|
||||
#### get\_default
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_default(cls, use_server: bool = False) -> Any
|
||||
```
|
||||
|
||||
Return default value for a field.
|
||||
If the field is Callable the function is called and actual result is returned.
|
||||
Used to populate default_values for pydantic Model in ormar Model Metaclass.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `use_server (bool)`: flag marking if server_default should be
|
||||
treated as default value, default False
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Any)`: default value for the field if set, otherwise implicit None
|
||||
|
||||
<a name="fields.base.BaseField.has_default"></a>
|
||||
#### has\_default
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| has_default(cls, use_server: bool = True) -> bool
|
||||
```
|
||||
|
||||
Checks if the field has default value set.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `use_server (bool)`: flag marking if server_default should be
|
||||
treated as default value, default False
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: result of the check if default value is set
|
||||
|
||||
<a name="fields.base.BaseField.is_auto_primary_key"></a>
|
||||
#### is\_auto\_primary\_key
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| is_auto_primary_key(cls) -> bool
|
||||
```
|
||||
|
||||
Checks if field is first a primary key and if it,
|
||||
it's than check if it's set to autoincrement.
|
||||
Autoincrement primary_key is nullable/optional.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: result of the check for primary key and autoincrement
|
||||
|
||||
<a name="fields.base.BaseField.construct_constraints"></a>
|
||||
#### construct\_constraints
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| construct_constraints(cls) -> List
|
||||
```
|
||||
|
||||
Converts list of ormar constraints into sqlalchemy ForeignKeys.
|
||||
Has to be done dynamically as sqlalchemy binds ForeignKey to the table.
|
||||
And we need a new ForeignKey for subclasses of current model
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(List[sqlalchemy.schema.ForeignKey])`: List of sqlalchemy foreign keys - by default one.
|
||||
|
||||
<a name="fields.base.BaseField.get_column"></a>
|
||||
#### get\_column
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column(cls, name: str) -> sqlalchemy.Column
|
||||
```
|
||||
|
||||
Returns definition of sqlalchemy.Column used in creation of sqlalchemy.Table.
|
||||
Populates name, column type constraints, as well as a number of parameters like
|
||||
primary_key, index, unique, nullable, default and server_default.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `name (str)`: name of the db column - used if alias is not set
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy.Column)`: actual definition of the database column as sqlalchemy requires.
|
||||
|
||||
<a name="fields.base.BaseField.expand_relationship"></a>
|
||||
#### expand\_relationship
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| expand_relationship(cls, value: Any, child: Union["Model", "NewBaseModel"], to_register: bool = True, relation_name: str = None) -> Any
|
||||
```
|
||||
|
||||
Function overwritten for relations, in basic field the value is returned as is.
|
||||
For relations the child model is first constructed (if needed),
|
||||
registered in relation and returned.
|
||||
For relation fields the value can be a pk value (Any type of field),
|
||||
dict (from Model) or actual instance/list of a "Model".
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `value (Any)`: a Model field value, returned untouched for non relation fields.
|
||||
- `child (Union["Model", "NewBaseModel"])`: a child Model to register
|
||||
- `to_register (bool)`: flag if the relation should be set in RelationshipManager
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Any)`: returns untouched value for normal fields, expands only for relations
|
||||
|
||||
28
docs/api/fields/decorators.md
Normal file
28
docs/api/fields/decorators.md
Normal file
@ -0,0 +1,28 @@
|
||||
<a name="decorators.property_field"></a>
|
||||
# decorators.property\_field
|
||||
|
||||
<a name="decorators.property_field.property_field"></a>
|
||||
#### property\_field
|
||||
|
||||
```python
|
||||
property_field(func: Callable) -> Union[property, Callable]
|
||||
```
|
||||
|
||||
Decorator to set a property like function on Model to be exposed
|
||||
as field in dict() and fastapi response.
|
||||
Although you can decorate a @property field like this and this will work,
|
||||
mypy validation will complain about this.
|
||||
Note that "fields" exposed like this do not go through validation.
|
||||
|
||||
**Raises**:
|
||||
|
||||
- `ModelDefinitionError`: if method has any other argument than self.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `func (Callable)`: decorated function to be exposed
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Union[property, Callable])`: decorated function passed in func param, with set __property_field__ = True
|
||||
|
||||
267
docs/api/fields/foreign-key.md
Normal file
267
docs/api/fields/foreign-key.md
Normal file
@ -0,0 +1,267 @@
|
||||
<a name="fields.foreign_key"></a>
|
||||
# fields.foreign\_key
|
||||
|
||||
<a name="fields.foreign_key.create_dummy_instance"></a>
|
||||
#### create\_dummy\_instance
|
||||
|
||||
```python
|
||||
create_dummy_instance(fk: Type["Model"], pk: Any = None) -> "Model"
|
||||
```
|
||||
|
||||
Ormar never returns you a raw data.
|
||||
So if you have a related field that has a value populated
|
||||
it will construct you a Model instance out of it.
|
||||
|
||||
Creates a "fake" instance of passed Model from pk value.
|
||||
The instantiated Model has only pk value filled.
|
||||
To achieve this __pk_only__ flag has to be passed as it skips the validation.
|
||||
|
||||
If the nested related Models are required they are set with -1 as pk value.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `fk (Model class)`: class of the related Model to which instance should be constructed
|
||||
- `pk (Any)`: value of the primary_key column
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Model)`: Model instance populated with only pk
|
||||
|
||||
<a name="fields.foreign_key.create_dummy_model"></a>
|
||||
#### create\_dummy\_model
|
||||
|
||||
```python
|
||||
create_dummy_model(base_model: Type["Model"], pk_field: Type[Union[BaseField, "ForeignKeyField", "ManyToManyField"]]) -> Type["BaseModel"]
|
||||
```
|
||||
|
||||
Used to construct a dummy pydantic model for type hints and pydantic validation.
|
||||
Populates only pk field and set it to desired type.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `base_model (Model class)`: class of target dummy model
|
||||
- `pk_field (Type[Union[BaseField, "ForeignKeyField", "ManyToManyField"]])`: ormar Field to be set on pydantic Model
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(pydantic.BaseModel)`: constructed dummy model
|
||||
|
||||
<a name="fields.foreign_key.UniqueColumns"></a>
|
||||
## UniqueColumns Objects
|
||||
|
||||
```python
|
||||
class UniqueColumns(UniqueConstraint)
|
||||
```
|
||||
|
||||
Subclass of sqlalchemy.UniqueConstraint.
|
||||
Used to avoid importing anything from sqlalchemy by user.
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyConstraint"></a>
|
||||
## ForeignKeyConstraint Objects
|
||||
|
||||
```python
|
||||
@dataclass
|
||||
class ForeignKeyConstraint()
|
||||
```
|
||||
|
||||
Internal container to store ForeignKey definitions used later
|
||||
to produce sqlalchemy.ForeignKeys
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyConstraint.name"></a>
|
||||
#### name
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyConstraint.ondelete"></a>
|
||||
#### ondelete
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyConstraint.onupdate"></a>
|
||||
#### onupdate
|
||||
|
||||
<a name="fields.foreign_key.ForeignKey"></a>
|
||||
#### ForeignKey
|
||||
|
||||
```python
|
||||
ForeignKey(to: Type["Model"], *, name: str = None, unique: bool = False, nullable: bool = True, related_name: str = None, virtual: bool = False, onupdate: str = None, ondelete: str = None, **kwargs: Any, ,) -> Any
|
||||
```
|
||||
|
||||
Despite a name it's a function that returns constructed ForeignKeyField.
|
||||
This function is actually used in model declaration (as ormar.ForeignKey(ToModel)).
|
||||
|
||||
Accepts number of relation setting parameters as well as all BaseField ones.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `to (Model class)`: target related ormar Model
|
||||
- `name (str)`: name of the database field - later called alias
|
||||
- `unique (bool)`: parameter passed to sqlalchemy.ForeignKey, unique flag
|
||||
- `nullable (bool)`: marks field as optional/ required
|
||||
- `related_name (str)`: name of reversed FK relation populated for you on to model
|
||||
- `virtual (bool)`: marks if relation is virtual.
|
||||
It is for reversed FK and auto generated FK on through model in Many2Many relations.
|
||||
- `onupdate (str)`: parameter passed to sqlalchemy.ForeignKey.
|
||||
How to treat child rows on update of parent (the one where FK is defined) model.
|
||||
- `ondelete (str)`: parameter passed to sqlalchemy.ForeignKey.
|
||||
How to treat child rows on delete of parent (the one where FK is defined) model.
|
||||
- `kwargs (Any)`: all other args to be populated by BaseField
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ForeignKeyField)`: ormar ForeignKeyField with relation to selected model
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField"></a>
|
||||
## ForeignKeyField Objects
|
||||
|
||||
```python
|
||||
class ForeignKeyField(BaseField)
|
||||
```
|
||||
|
||||
Actual class returned from ForeignKey function call and stored in model_fields.
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField.to"></a>
|
||||
#### to
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField.name"></a>
|
||||
#### name
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField.related_name"></a>
|
||||
#### related\_name
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField.virtual"></a>
|
||||
#### virtual
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField._extract_model_from_sequence"></a>
|
||||
#### \_extract\_model\_from\_sequence
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| _extract_model_from_sequence(cls, value: List, child: "Model", to_register: bool, relation_name: str) -> List["Model"]
|
||||
```
|
||||
|
||||
Takes a list of Models and registers them on parent.
|
||||
Registration is mutual, so children have also reference to parent.
|
||||
|
||||
Used in reverse FK relations.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `value (List)`: list of Model
|
||||
- `child (Model)`: child/ related Model
|
||||
- `to_register (bool)`: flag if the relation should be set in RelationshipManager
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(List["Model"])`: list (if needed) registered Models
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField._register_existing_model"></a>
|
||||
#### \_register\_existing\_model
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| _register_existing_model(cls, value: "Model", child: "Model", to_register: bool, relation_name: str) -> "Model"
|
||||
```
|
||||
|
||||
Takes already created instance and registers it for parent.
|
||||
Registration is mutual, so children have also reference to parent.
|
||||
|
||||
Used in reverse FK relations and normal FK for single models.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `value (Model)`: already instantiated Model
|
||||
- `child (Model)`: child/ related Model
|
||||
- `to_register (bool)`: flag if the relation should be set in RelationshipManager
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Model)`: (if needed) registered Model
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField._construct_model_from_dict"></a>
|
||||
#### \_construct\_model\_from\_dict
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| _construct_model_from_dict(cls, value: dict, child: "Model", to_register: bool, relation_name: str) -> "Model"
|
||||
```
|
||||
|
||||
Takes a dictionary, creates a instance and registers it for parent.
|
||||
If dictionary contains only one field and it's a pk it is a __pk_only__ model.
|
||||
Registration is mutual, so children have also reference to parent.
|
||||
|
||||
Used in normal FK for dictionaries.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `value (dict)`: dictionary of a Model
|
||||
- `child (Model)`: child/ related Model
|
||||
- `to_register (bool)`: flag if the relation should be set in RelationshipManager
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Model)`: (if needed) registered Model
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField._construct_model_from_pk"></a>
|
||||
#### \_construct\_model\_from\_pk
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| _construct_model_from_pk(cls, value: Any, child: "Model", to_register: bool, relation_name: str) -> "Model"
|
||||
```
|
||||
|
||||
Takes a pk value, creates a dummy instance and registers it for parent.
|
||||
Registration is mutual, so children have also reference to parent.
|
||||
|
||||
Used in normal FK for dictionaries.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `value (Any)`: value of a related pk / fk column
|
||||
- `child (Model)`: child/ related Model
|
||||
- `to_register (bool)`: flag if the relation should be set in RelationshipManager
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Model)`: (if needed) registered Model
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField.register_relation"></a>
|
||||
#### register\_relation
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| register_relation(cls, model: "Model", child: "Model", relation_name: str) -> None
|
||||
```
|
||||
|
||||
Registers relation between parent and child in relation manager.
|
||||
Relation manager is kep on each model (different instance).
|
||||
|
||||
Used in Metaclass and sometimes some relations are missing
|
||||
(i.e. cloned Models in fastapi might miss one).
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `model (Model class)`: parent model (with relation definition)
|
||||
- `child (Model class)`: child model
|
||||
|
||||
<a name="fields.foreign_key.ForeignKeyField.expand_relationship"></a>
|
||||
#### expand\_relationship
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| expand_relationship(cls, value: Any, child: Union["Model", "NewBaseModel"], to_register: bool = True, relation_name: str = None) -> Optional[Union["Model", List["Model"]]]
|
||||
```
|
||||
|
||||
For relations the child model is first constructed (if needed),
|
||||
registered in relation and returned.
|
||||
For relation fields the value can be a pk value (Any type of field),
|
||||
dict (from Model) or actual instance/list of a "Model".
|
||||
|
||||
Selects the appropriate constructor based on a passed value.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `value (Any)`: a Model field value, returned untouched for non relation fields.
|
||||
- `child (Union["Model", "NewBaseModel"])`: a child Model to register
|
||||
- `to_register (bool)`: flag if the relation should be set in RelationshipManager
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(Optional[Union["Model", List["Model"]]])`: returns a Model or a list of Models
|
||||
|
||||
59
docs/api/fields/many-to-many.md
Normal file
59
docs/api/fields/many-to-many.md
Normal file
@ -0,0 +1,59 @@
|
||||
<a name="fields.many_to_many"></a>
|
||||
# fields.many\_to\_many
|
||||
|
||||
<a name="fields.many_to_many.REF_PREFIX"></a>
|
||||
#### REF\_PREFIX
|
||||
|
||||
<a name="fields.many_to_many.ManyToMany"></a>
|
||||
#### ManyToMany
|
||||
|
||||
```python
|
||||
ManyToMany(to: Type["Model"], through: Type["Model"], *, name: str = None, unique: bool = False, virtual: bool = False, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Despite a name it's a function that returns constructed ManyToManyField.
|
||||
This function is actually used in model declaration
|
||||
(as ormar.ManyToMany(ToModel, through=ThroughModel)).
|
||||
|
||||
Accepts number of relation setting parameters as well as all BaseField ones.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `to (Model class)`: target related ormar Model
|
||||
- `through (Model class)`: through model for m2m relation
|
||||
- `name (str)`: name of the database field - later called alias
|
||||
- `unique (bool)`: parameter passed to sqlalchemy.ForeignKey, unique flag
|
||||
- `virtual (bool)`: marks if relation is virtual.
|
||||
It is for reversed FK and auto generated FK on through model in Many2Many relations.
|
||||
- `kwargs (Any)`: all other args to be populated by BaseField
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(ManyToManyField)`: ormar ManyToManyField with m2m relation to selected model
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField"></a>
|
||||
## ManyToManyField Objects
|
||||
|
||||
```python
|
||||
class ManyToManyField(ForeignKeyField, ormar.QuerySetProtocol, ormar.RelationProtocol)
|
||||
```
|
||||
|
||||
Actual class returned from ManyToMany function call and stored in model_fields.
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.through"></a>
|
||||
#### through
|
||||
|
||||
<a name="fields.many_to_many.ManyToManyField.default_target_field_name"></a>
|
||||
#### default\_target\_field\_name
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| default_target_field_name(cls) -> str
|
||||
```
|
||||
|
||||
Returns default target model name on through model.
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(str)`: name of the field
|
||||
|
||||
514
docs/api/fields/model-fields.md
Normal file
514
docs/api/fields/model-fields.md
Normal file
@ -0,0 +1,514 @@
|
||||
<a name="fields.model_fields"></a>
|
||||
# fields.model\_fields
|
||||
|
||||
<a name="fields.model_fields.is_field_nullable"></a>
|
||||
#### is\_field\_nullable
|
||||
|
||||
```python
|
||||
is_field_nullable(nullable: Optional[bool], default: Any, server_default: Any, pydantic_only: Optional[bool]) -> bool
|
||||
```
|
||||
|
||||
Checks if the given field should be nullable/ optional based on parameters given.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `nullable (Optional[bool])`: flag explicit setting a column as nullable
|
||||
- `default (Any)`: value or function to be called as default in python
|
||||
- `server_default (Any)`: function to be called as default by sql server
|
||||
- `pydantic_only (Optional[bool])`: flag if fields should not be included in the sql table
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: result of the check
|
||||
|
||||
<a name="fields.model_fields.is_auto_primary_key"></a>
|
||||
#### is\_auto\_primary\_key
|
||||
|
||||
```python
|
||||
is_auto_primary_key(primary_key: bool, autoincrement: bool) -> bool
|
||||
```
|
||||
|
||||
Checks if field is an autoincrement pk -> if yes it's optional.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `primary_key (bool)`: flag if field is a pk field
|
||||
- `autoincrement (bool)`: flag if field should be autoincrement
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(bool)`: result of the check
|
||||
|
||||
<a name="fields.model_fields.ModelFieldFactory"></a>
|
||||
## ModelFieldFactory Objects
|
||||
|
||||
```python
|
||||
class ModelFieldFactory()
|
||||
```
|
||||
|
||||
Default field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.ModelFieldFactory._bases"></a>
|
||||
#### \_bases
|
||||
|
||||
<a name="fields.model_fields.ModelFieldFactory._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.ModelFieldFactory.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *args: Any, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.ModelFieldFactory.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.ModelFieldFactory.validate"></a>
|
||||
#### validate
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| validate(cls, **kwargs: Any) -> None
|
||||
```
|
||||
|
||||
Used to validate if all required parameters on a given field type are set.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: all params passed during construction
|
||||
|
||||
<a name="fields.model_fields.String"></a>
|
||||
## String Objects
|
||||
|
||||
```python
|
||||
class String(ModelFieldFactory, str)
|
||||
```
|
||||
|
||||
String field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.String._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.String.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, allow_blank: bool = True, strip_whitespace: bool = False, min_length: int = None, max_length: int = None, curtail_length: int = None, regex: str = None, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.String.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.String.validate"></a>
|
||||
#### validate
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| validate(cls, **kwargs: Any) -> None
|
||||
```
|
||||
|
||||
Used to validate if all required parameters on a given field type are set.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: all params passed during construction
|
||||
|
||||
<a name="fields.model_fields.Integer"></a>
|
||||
## Integer Objects
|
||||
|
||||
```python
|
||||
class Integer(ModelFieldFactory, int)
|
||||
```
|
||||
|
||||
Integer field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.Integer._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.Integer.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, minimum: int = None, maximum: int = None, multiple_of: int = None, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.Integer.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.Text"></a>
|
||||
## Text Objects
|
||||
|
||||
```python
|
||||
class Text(ModelFieldFactory, str)
|
||||
```
|
||||
|
||||
Text field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.Text._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.Text.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, allow_blank: bool = True, strip_whitespace: bool = False, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.Text.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.Float"></a>
|
||||
## Float Objects
|
||||
|
||||
```python
|
||||
class Float(ModelFieldFactory, float)
|
||||
```
|
||||
|
||||
Float field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.Float._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.Float.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, minimum: float = None, maximum: float = None, multiple_of: int = None, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.Float.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.DateTime"></a>
|
||||
## DateTime Objects
|
||||
|
||||
```python
|
||||
class DateTime(ModelFieldFactory, datetime.datetime)
|
||||
```
|
||||
|
||||
DateTime field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.DateTime._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.DateTime.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.Date"></a>
|
||||
## Date Objects
|
||||
|
||||
```python
|
||||
class Date(ModelFieldFactory, datetime.date)
|
||||
```
|
||||
|
||||
Date field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.Date._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.Date.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.Time"></a>
|
||||
## Time Objects
|
||||
|
||||
```python
|
||||
class Time(ModelFieldFactory, datetime.time)
|
||||
```
|
||||
|
||||
Time field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.Time._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.Time.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.JSON"></a>
|
||||
## JSON Objects
|
||||
|
||||
```python
|
||||
class JSON(ModelFieldFactory, pydantic.Json)
|
||||
```
|
||||
|
||||
JSON field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.JSON._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.JSON.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.BigInteger"></a>
|
||||
## BigInteger Objects
|
||||
|
||||
```python
|
||||
class BigInteger(Integer, int)
|
||||
```
|
||||
|
||||
BigInteger field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.BigInteger._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.BigInteger.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, minimum: int = None, maximum: int = None, multiple_of: int = None, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.BigInteger.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.Decimal"></a>
|
||||
## Decimal Objects
|
||||
|
||||
```python
|
||||
class Decimal(ModelFieldFactory, decimal.Decimal)
|
||||
```
|
||||
|
||||
Decimal field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.Decimal._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.Decimal.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, minimum: float = None, maximum: float = None, multiple_of: int = None, precision: int = None, scale: int = None, max_digits: int = None, decimal_places: int = None, **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.Decimal.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
<a name="fields.model_fields.Decimal.validate"></a>
|
||||
#### validate
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| validate(cls, **kwargs: Any) -> None
|
||||
```
|
||||
|
||||
Used to validate if all required parameters on a given field type are set.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: all params passed during construction
|
||||
|
||||
<a name="fields.model_fields.UUID"></a>
|
||||
## UUID Objects
|
||||
|
||||
```python
|
||||
class UUID(ModelFieldFactory, uuid.UUID)
|
||||
```
|
||||
|
||||
UUID field factory that construct Field classes and populated their values.
|
||||
|
||||
<a name="fields.model_fields.UUID._type"></a>
|
||||
#### \_type
|
||||
|
||||
<a name="fields.model_fields.UUID.__new__"></a>
|
||||
#### \_\_new\_\_
|
||||
|
||||
```python
|
||||
| __new__(cls, *, uuid_format: str = "hex", **kwargs: Any) -> Type[BaseField]
|
||||
```
|
||||
|
||||
<a name="fields.model_fields.UUID.get_column_type"></a>
|
||||
#### get\_column\_type
|
||||
|
||||
```python
|
||||
| @classmethod
|
||||
| get_column_type(cls, **kwargs: Any) -> Any
|
||||
```
|
||||
|
||||
Return proper type of db column for given field type.
|
||||
Accepts required and optional parameters that each column type accepts.
|
||||
|
||||
**Arguments**:
|
||||
|
||||
- `kwargs (Any)`: key, value pairs of sqlalchemy options
|
||||
|
||||
**Returns**:
|
||||
|
||||
`(sqlalchemy Column)`: initialized column with proper options
|
||||
|
||||
Reference in New Issue
Block a user