Skip to main content

Convenient fields and classes for handling measurements

Project description

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:

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"{self.name} of {self.volume}"

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

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

>>> 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)
>>> added_together.kg  # 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.

Download files

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

Source Distribution

django-measurement-3.2.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

django_measurement-3.2.3-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-measurement-3.2.3.tar.gz.

File metadata

  • Download URL: django-measurement-3.2.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for django-measurement-3.2.3.tar.gz
Algorithm Hash digest
SHA256 8fda226239a4d4ac033270e5bbd5aa3595c1c817f47a657c83f343b492b88220
MD5 df00247a5e6b84cc788cd7029ac1a5ba
BLAKE2b-256 46e3050ecfb46394f388ce144e967d35f14e046e6581465dec59685d591658b9

See more details on using hashes here.

Provenance

File details

Details for the file django_measurement-3.2.3-py2.py3-none-any.whl.

File metadata

  • Download URL: django_measurement-3.2.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for django_measurement-3.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 aca86e10dc603ea53595ca80aaa43824480342d969e469f4ec83b12df3bad65b
MD5 fff4d16b60145f825d94f18ff4e61df9
BLAKE2b-256 826536827e8bae6eea3c206c8d4841516741934ee02e8707f62f41fa60cd73ed

See more details on using hashes here.

Provenance

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