Skip to main content

Field for Django models that stores multidimensional physical quantities

Project description

A Django application providing model and form field to accept and store multidimensional physical quantities.

Requirements

This application depends on Pint library, used for operate and manipulate physical quantities. Full documentation is available at http://pint.readthedocs.org/

Installation

Install django-quantity-field using pip: pip install django-quantity-field.

Usage

In order to use a quantity field add it to your model definition:

from quantity_field import ureg
from quantity_field.fields import MultiQuantityField

class Package(models.Model):
    size = MultiQuantityField(dim=3, units=(ureg.mm, ureg.cm, ureg.m))
    weight = MultiQuantityField(units=(ureg.g, ureg.kg))

django-quantity-field comes with the custom form field that is used by default for editing in admin or in your forms.

Accessing MultiQuantityField field will returns MultiQuantity object that can be used as ordinary Pint quantities.

>>> from quantity_field.base import MultiQuantity
>>> size = MultiQuantity.from_list(2, 5.5, 4, str(ureg.m))
>>> size
<Quantity(44.0, 'meter ** 3')>
>>> size.dim
3
>>> [v for v in size]
[<Quantity(2.0, 'meter')>, <Quantity(5.5, 'meter')>, <Quantity(4.0, 'meter')>]

Warning

Don’t forget there are no global units in Pint. To use Pint quantities in your project side by side with django-quantity-field use Pint registry from our application.

>>> from quantity_field import ureg
>>> from quantity_field.base import MultiQuantity
>>> box = MultiQuantity.from_string('42 kg')
>>> box + 2.2 * ureg.kg
<Quantity(44.2, 'kilogram')>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-quantity-field-1.0.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

django_quantity_field-1.0.1-py2-none-any.whl (8.4 kB view details)

Uploaded Python 2

File details

Details for the file django-quantity-field-1.0.1.tar.gz.

File metadata

File hashes

Hashes for django-quantity-field-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b19a039a8d7c7cbee3269c296c3c34c7add5d8d705412cc9d8db76f8669d2bb0
MD5 e0fd97a70c004ff89c1e93f227dea063
BLAKE2b-256 d9356f7fb9971193e3acfc86e66ce0b5e0e2f4f1082443dfb4d22d8a121c6260

See more details on using hashes here.

File details

Details for the file django_quantity_field-1.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for django_quantity_field-1.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 054c8b325e10c06987424d0a970a19d18c39c0bb0c30b93578db030417d740f0
MD5 14e48e26a03f84f36c77409855a773b8
BLAKE2b-256 8ae1b4eeeb61e2d75d5d3660f6682f5ccb4484b1b2213fb86e4101b179afc4c4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page