quantityfield package
Submodules
quantityfield.fields module
- class quantityfield.fields.BigIntegerQuantityField(base_units: str, *args, unit_choices: Optional[Iterable[str]] = None, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFieldMixin
,django.db.models.fields.BigIntegerField
- form_field_class
- class quantityfield.fields.DecimalQuantityField(base_units: str, *args, unit_choices: Optional[List[str]] = None, verbose_name: Optional[str] = None, name: Optional[str] = None, max_digits: Optional[int] = None, decimal_places: Optional[int] = None, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFieldMixin
,django.db.models.fields.DecimalField
- form_field_class
- get_db_prep_save(value, connection) decimal.Decimal [source]
Get Value that shall be saved to database, make sure it is transformed
- to_number_type
alias of
decimal.Decimal
- class quantityfield.fields.DecimalQuantityFormField(*args, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFormFieldMixin
,django.forms.fields.DecimalField
- to_number_type
alias of
decimal.Decimal
- class quantityfield.fields.IntegerQuantityField(base_units: str, *args, unit_choices: Optional[Iterable[str]] = None, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFieldMixin
,django.db.models.fields.IntegerField
- form_field_class
- class quantityfield.fields.IntegerQuantityFormField(*args, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFormFieldMixin
,django.forms.fields.IntegerField
- class quantityfield.fields.PositiveIntegerQuantityField(base_units: str, *args, unit_choices: Optional[Iterable[str]] = None, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFieldMixin
,django.db.models.fields.PositiveIntegerField
- form_field_class
- class quantityfield.fields.QuantityField(base_units: str, *args, unit_choices: Optional[Iterable[str]] = None, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFieldMixin
,django.db.models.fields.FloatField
- form_field_class
- class quantityfield.fields.QuantityFieldMixin(base_units: str, *args, unit_choices: Optional[Iterable[str]] = None, **kwargs)[source]
Bases:
object
- clean(value, model_instance) pint.quantity.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[Union[Sequence[Union[None, bool, str, int, float, complex, datetime.datetime]], Dict[str, Union[None, bool, str, int, float, complex, datetime.datetime]]]], Dict[str, Union[Sequence[Union[None, bool, str, int, float, complex, datetime.datetime]], Dict[str, Union[None, bool, str, int, float, complex, datetime.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: pint.quantity.Quantity) pint.quantity.Quantity [source]
Check if the UnitRegistry from settings is used. If not try to fix it but give a warning.
- get_prep_value(value: Any) Optional[Union[int, float, decimal.Decimal]] [source]
Perform preliminary non-db specific value checks and conversions.
Make sure that we compare/use only values without a unit
- run_validators: Callable
A Django Model Field that resolves to a pint Quantity object
- to_number_type: Callable[[Any], Union[int, float, decimal.Decimal]]
- validate: Callable
- value_from_object: Callable[[Any], Any]
- class quantityfield.fields.QuantityFormField(*args, **kwargs)[source]
Bases:
quantityfield.fields.QuantityFormFieldMixin
,django.forms.fields.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
- clean(value)[source]
General idea, first try to extract the correct number like done in the other classes and then follow the same procedure as in the django default field
- empty_values: Sequence[Any]
- run_validators: Callable
- to_number_type: Callable[[Any], Union[int, float, decimal.Decimal]]
- validate: Callable
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:
django.forms.widgets.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.