Skip to main content

Convenient fields and classes for handling measurements

Project description

https://travis-ci.org/coddingtonbear/django-measurement.png?branch=master https://pypip.in/v/django-measurement/badge.png https://pypip.in/d/django-measurement/badge.png https://pypip.in/license/django-measurement/badge.png

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 django_measurement.measure 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 django_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.1.0.tar.gz (4.5 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-measurement-2.1.0.tar.gz
Algorithm Hash digest
SHA256 cd7b8ea5a4544a0ea28260ff2f724725faaebc952f482945218918748eac0a8e
MD5 e3a2c5dec35c9724770efd3a898bf68b
BLAKE2b-256 f55868d2b65475dfd18d81dd9f0b43b0bd220ee2c3c76d51748423163bb27b26

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