Fields
Base Field
- class nyoibo.fields.Field
Base Field
This is the base for all field types.
- _internal_type
each
Fieldsubclass must to override this attribute with the internal type that field represent.
- _exceptions
possible exception that could be raised when field tries to cast to
_internal_type.- Type:
tuple
- Parameters:
private (bool) – set if field is private or not. When
private=Truegetter and setters will not be created.Falseby default.mutable (bool) – set if field is mutable or not. When
mutable=Falsesetter will not be created.Falseby default.default_value (any) – default value to field.
choices (Enum) – value to this field must be a Enum key or Enum value.
required (bool) – validate if value is not None.
Falseby default.
- parse()
Parse and cast to
_internal_type- Parameters:
value (any) – value to parse.
- Returns:
_internal_typeif the casting was successful- Raises:
FieldValueError – if the casting failed.
RequiredValueError – if a field has required = True and value is None
String Field
- class nyoibo.fields.StrField
Field for string values
- Parameters:
max_length (int) – maximum lenght for str value
- Raises:
AssertionError – if
max_lengthis less than 0.
- parse()
Parse and cast to
_internal_type- Parameters:
value (any) – value to parse.
- Returns:
_internal_typeif the casting was successful- Raises:
FieldValueError – if the casting failed.
RequiredValueError – if a field has required = True and value is None
Integer Field
- class nyoibo.fields.IntField
Field for integer values
- Parameters:
min_value (int) – minimum value
max_value (int) – maximum value
- Raises:
AssertionError – if
min_valueormax_valueare no integer.
- parse()
Parse and cast to integers
- Parameters:
value (any) – value to cast
- Returns:
(int) casted value
- Raises:
IntMinValueError – if
min_valuewas set andvalueis less thanmin_value.IntMaxValueError – if
max_valuewas set andvalueis greater thanmax_value.
Boolean Field
- class nyoibo.fields.BoolField
Field for boolean values
Date Field
Datetime Field
Float Field
- class nyoibo.fields.FloatField
Field for float values
Decimal Field
- class nyoibo.fields.DecimalField
Field for Decimal values
Link Field
- class nyoibo.fields.LinkField
Field for link between other
Entity- Parameters:
to (Entity) – Entity instance
- Raises:
ValueError – if
tois not a subclass of :ref:entity
- parse()
Parse and cast to
_internal_type- Parameters:
value (any) – value to parse.
- Returns:
_internal_typeif the casting was successful- Raises:
FieldValueError – if the casting failed.
RequiredValueError – if a field has required = True and value is None
Dict Field
- class nyoibo.fields.DictField
Field for dict values
JSON Field
- class nyoibo.fields.JSONField
Field for json values.
Tuple Field
- class nyoibo.fields.TupleField
Field for tuple values
- Parameters:
of – Type of items. All items going to be cast to
oftype.reverse_relationship (bool) – create a reverse relation with
of.
- Raises:
ValueError – if of is
Noneandreverse_relationshipis True
List Field
- class nyoibo.fields.ListField
Field for list values
- Parameters:
of – Type of items. All items going to be cast to
oftype. reverse_relationship (bool): create a reverse relation withof.- Raises:
ValueError – if of is
Noneandreverse_relationshipis True