Skip to main content

Convenient fields and classes for handling measurements

Project description

https://travis-ci.org/coddingtonbear/django-measurement.png?branch=master

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

Note: Version 2.0 has no backward compatibility due to major design changes.

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(Volume)

    def __unicode__(self):
        return u"%s of %s" % (self.name, 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 Weight
>>> weight_1 = Weight(lb=125)
>>> weight_2 = Weight(kg=40)
>>> added_together = weight_1 + weight_2
>>> added_together
Weight(lb=213.184976807)
>>> added_together.kg  # Maybe I actually need this value in kg?
96.699
  • Documentation for django-measurement is available an ReadTheDocs.

  • Please post issues on Github.

  • Test status available on Travis-CI.

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-measurement-2.3.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

django_measurement-2.3.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django-measurement-2.3.0.tar.gz
Algorithm Hash digest
SHA256 f370ed67f84530ea15c65bc906a76ac8384e4def38ef6c51653c2bf39587c3aa
MD5 80364f645cc735521601a74b89344282
BLAKE2b-256 5f94ce61a942e799ab0daf78b1b381839274cd3ebec0b39b1abd5b254063bf85

See more details on using hashes here.

Provenance

File details

Details for the file django_measurement-2.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_measurement-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 021ce31581dac0564c934c96a4728d57a043f4e2ad9c69c59a979070be099de6
MD5 d3787c63a7896bca871d4d774c26b53f
BLAKE2b-256 d0712c92cbdaf9588524284b4b65b0a5308aa9e4383614983f20d87e80843123

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