Skip to main content

Convenient fields and classes for handling measurements

Project description

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

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

Note: Currently, this is not compatible with Django 1.6 or later. For more information, please follow the issue tracking this limitation.

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.fields import MeasurementField
from measurement.measures import Volume
from django.db.models import Model

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

    def __str__(self):
        return '%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.

Bitdeli badge

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-1.3.3.tar.gz (8.2 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-measurement-1.3.3.tar.gz
Algorithm Hash digest
SHA256 26536ca9da2d48065d6e838a8714c3986f03c30fef99751d8231de17fed628e5
MD5 e77fba3c3cac3aa949894c6008580b33
BLAKE2b-256 0638b3580f92d9ceda508fa39e8f91ddd2fa3251e27688f16ff7c4124b695b20

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