Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Easily store, retrieve, and convert measurements of weight, volume, distance, area and more.
Python
branch: master

Merge pull request #8 from codingjoe/master

I decided to merge is as the discussion about saving the selected unit didn't produce any code.
@coddingtonbear would you be so kind to release or add me as a pypi maintainer?
latest commit 6e670a4e90
@codingjoe codingjoe authored
Failed to load latest commit information.
django_measurement Finilizing v2.0
docs Finilizing v2.0
tests Finilizing v2.0
.gitignore add pytest cache to gitignore
.travis.yml Removed python 3.4 from tests
LICENSE Adding license file.
MANIFEST
MANIFEST.in Use python-measurement for measurement objects.
pytest.ini Finilizing v2.0
readme.rst Finilizing v2.0
requirements.txt Bumping version number; bumping python-measurement requirement.
runtests.py version 1.6 preview
setup.py Finilizing v2.0

readme.rst

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.
Something went wrong with that request. Please try again.