Fields types

Fields to be used with dirty models.

class dirty_models.fields.IntegerField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.BaseField

It allows to use an integer as value in a field.

Automatic cast from:

  • float
  • str if all characters are digits
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.FloatField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.BaseField

It allows to use a float as value in a field.

Automatic cast from:

  • int
  • str if all characters are digits and there is only one dot (.).
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.BooleanField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.BaseField

It allows to use a boolean as value in a field.

Automatic cast from:

  • int 0 become False, anything else True
  • str true and yes become True, anything else False. It is case-insensitive.
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.StringField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.BaseField

It allows to use a string as value in a field.

Automatic cast from:

  • int
  • float
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.StringIdField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.StringField

It allows to use a string as value in a field, but not allows empty strings. Empty string are like None and they will remove data of field.

Automatic cast from:

  • int
  • float
  • Enum if value of enum can be cast.
set_value(obj, value)[source]

Sets value to model if not empty

class dirty_models.fields.TimeField(parse_format=None, default_timezone=None, **kwargs)[source]

Bases: dirty_models.fields.DateTimeBaseField

It allows to use a time as value in a field.

Automatic cast from:

  • list items will be used to construct time object as arguments.
  • dict items will be used to construct time object as keyword arguments.
  • str will be parsed using a function or format in parser constructor parameter.
  • int will be used as timestamp.
  • datetime will get time part.
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

set_value(obj, value: datetime.time)[source]

Sets value to model

class dirty_models.fields.DateField(parse_format=None, **kwargs)[source]

Bases: dirty_models.fields.DateTimeBaseField

It allows to use a date as value in a field.

Automatic cast from:

  • list items will be used to construct date object as arguments.
  • dict items will be used to construct date object as keyword arguments.
  • str will be parsed using a function or format in parser constructor parameter.
  • int will be used as timestamp.
  • datetime will get date part.
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.DateTimeField(parse_format=None, default_timezone=None, force_timezone=False, **kwargs)[source]

Bases: dirty_models.fields.DateTimeBaseField

It allows to use a datetime as value in a field.

Automatic cast from:

  • list items will be used to construct datetime object as arguments.
  • dict items will be used to construct datetime object as keyword arguments.
  • str will be parsed using a function or format in parser constructor parameter.
  • int will be used as timestamp.
  • date will set date part.
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

set_value(obj, value)[source]

Sets value to model

class dirty_models.fields.TimedeltaField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.BaseField

It allows to use a timedelta as value in a field.

Automatic cast from:

  • float as seconds.
  • int as seconds.
  • Enum if value of enum can be cast.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.ModelField(model_class=None, **kwargs)[source]

Bases: dirty_models.fields.BaseField

It allows to use a model as value in a field. Model type must be defined on constructor using param model_class. If it is not defined self model will be used. It means model inside field will be the same class than model who define field.

Automatic cast from:

can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

model_class

Model_class getter: model class used on field

class dirty_models.fields.ArrayField(autolist=False, **kwargs)[source]

Bases: dirty_models.fields.InnerFieldTypeMixin, dirty_models.fields.BaseField

It allows to create a ListModel (iterable in dirty_models.types) of different elements according to the specified field_type. So it is possible to have a list of Integers, Strings, Models, etc. When using a model with no specified model_class the model inside field.

Automatic cast from:

autolist

autolist getter: autolist flag allows to convert a simple item on a list with one item.

can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.HashMapField(model_class=None, **kwargs)[source]

Bases: dirty_models.fields.InnerFieldTypeMixin, dirty_models.fields.ModelField

It allows to create a field which contains a hash map.

Automatic cast from:

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.BlobField(name=None, alias=None, getter=None, setter=None, read_only=False, default=None, doc=None)[source]

Bases: dirty_models.fields.BaseField

It allows any type of data.

class dirty_models.fields.MultiTypeField(field_types=None, **kwargs)[source]

Bases: dirty_models.fields.BaseField

It allows to define multiple type for a field. So, it is possible to define a field as a integer and as a model field, for example.

can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type

class dirty_models.fields.EnumField(enum_class, *args, **kwargs)[source]

Bases: dirty_models.fields.BaseField

It allows to create a field which contains a member of an enumeration.

Automatic cast from:

  • Any value of enumeration.
  • Any member name of enumeration.
can_use_value(value)[source]

Checks whether value could be converted to field’s type

check_value(value)[source]

Checks whether value is field’s type

convert_value(value)[source]

Converts value to field type