Easily store, retrieve, and convert measurements of weight, volume, distance, area and more.



|version| |ci| |coverage| |license|

Django Measurement

Easily use, manipulate, and store unit-aware measurement objects using Python and Django.

django.contrib.gis.measure <>_ has these wonderful 'Distance' objects that can be used not only for storing a unit-aware distance measurement, but also for converting between different units and adding/subtracting these objects from one another.

This module provides for a django model field and admin interface for storing any measurements provided by python-measurement_.

Example use with a model:

.. code-block:: python

from django_measurement.models import MeasurementField from measurement.measures import Volume from django.db import models

class BeerConsumptionLogEntry(models.Model): name = models.CharField(max_length=255) volume = MeasurementField(measurement=Volume)

   def __str__(self):
       return f"{} of {self.volume}"

entry = BeerConsumptionLogEntry() = "Bear Republic Racer 5" entry.volume = Volume(us_pint=1)

These stored measurement objects can be used in all of the usual ways supported by python-measurement_ too:

.. code-block:: python

from measurement.measures import Mass weight_1 = Mass(lb=125) weight_2 = Mass(kg=40) added_together = weight_1 + weight_2 added_together Mass(lb=213.18497680735112) # Maybe I actually need this value in kg? 96.699

  • Documentation for django-measurement is available via Read the Docs_.
  • Please post issues on GitHub_.

.. _Read the Docs: .. _GitHub: .. _python-measurement:

.. |version| image:: :target: .. |ci| image:: :target: .. |coverage| image:: :target: .. |license| image:: :target: LICENSE