quantityfield package
Submodules
quantityfield.fields module
- class quantityfield.fields.BigIntegerQuantityField(base_units: str, *args, unit_choices: Iterable[str] | None = None, **kwargs)[source]
Bases:
QuantityFieldMixin
,BigIntegerField
- form_field_class
alias of
IntegerQuantityFormField
- class quantityfield.fields.DecimalQuantityField(base_units: str, *args, unit_choices: List[str] | None = None, verbose_name: str = None, name: str = None, max_digits: int = None, decimal_places: int = None, **kwargs)[source]
Bases:
QuantityFieldMixin
,DecimalField
- form_field_class
alias of
DecimalQuantityFormField
- class quantityfield.fields.DecimalQuantityFormField(*args, **kwargs)[source]
Bases:
QuantityFormFieldMixin
,DecimalField
- class quantityfield.fields.IntegerQuantityField(base_units: str, *args, unit_choices: Iterable[str] | None = None, **kwargs)[source]
Bases:
QuantityFieldMixin
,IntegerField
- form_field_class
alias of
IntegerQuantityFormField
- class quantityfield.fields.IntegerQuantityFormField(*args, **kwargs)[source]
Bases:
QuantityFormFieldMixin
,IntegerField
- class quantityfield.fields.PositiveIntegerQuantityField(base_units: str, *args, unit_choices: Iterable[str] | None = None, **kwargs)[source]
Bases:
QuantityFieldMixin
,PositiveIntegerField
- form_field_class
alias of
IntegerQuantityFormField
- class quantityfield.fields.QuantityField(base_units: str, *args, unit_choices: Iterable[str] | None = None, **kwargs)[source]
Bases:
QuantityFieldMixin
,FloatField
- form_field_class
alias of
QuantityFormField
- class quantityfield.fields.QuantityFieldMixin(base_units: str, *args, unit_choices: Iterable[str] | None = None, **kwargs)[source]
Bases:
object
- clean(value, model_instance) Quantity [source]
Convert the value’s type and run validation. Validation errors from to_python() and validate() are propagated. Return the correct value if no error is raised.
This is a copy from djangos implementation but modified so that validators are only checked against the magnitude as otherwise the default database validators will not fail because of comparison errors
- deconstruct() Tuple[str, str, Sequence[Sequence[None | bool | str | int | float | complex | datetime] | Dict[str, None | bool | str | int | float | complex | datetime]], Dict[str, Sequence[None | bool | str | int | float | complex | datetime] | Dict[str, None | bool | str | int | float | complex | datetime]]] [source]
Return enough information to recreate the field as a 4-tuple:
The name of the field on the model, if contribute_to_class() has been run.
The import path of the field, including the class:e.g. django.db.models.IntegerField This should be the most portable version, so less specific may be better.
A list of positional arguments.
A dict of keyword arguments.
- fix_unit_registry(value: Quantity) Quantity [source]
Check if the UnitRegistry from settings is used. If not try to fix it but give a warning.
- class quantityfield.fields.QuantityFormField(*args, **kwargs)[source]
Bases:
QuantityFormFieldMixin
,FloatField
- class quantityfield.fields.QuantityFormFieldMixin(*args, **kwargs)[source]
Bases:
object
This formfield allows a user to choose which units they wish to use to enter a value, but the value is yielded in the base_units
quantityfield.helper module
quantityfield.settings module
quantityfield.units module
quantityfield.widgets module
- class quantityfield.widgets.QuantityWidget(*, attrs=None, base_units=None, allowed_types=None)[source]
Bases:
MultiWidget
- decompress(value)[source]
This function is called during rendering
It is responsible to split values for the two widgets
- property media
Media for a multiwidget is the combination of all media of the subwidgets.