Easily store, retrieve, and convert measurements of weight, volume, distance, area and more.
Python
Latest commit 863708b Jul 16, 2016 @iansprice iansprice committed with codingjoe Added bidimensional_separator setting/kwarg (#29)
* Added bidimensional_seperator kwarg

Added bidimensional_seperator kwarg to MeasurementField. This changes the option label upon rendering.

This can be defined two ways-
1. Add a setting "BIDIMENSIONAL_SEPERATOR" to settings.py, which will be default unless kwarg is supplied.
2. Passing kwarg bidimensional_seperator to instantiation of a particular MeasurementField.
Example- if kwarg bidimensional_seperator=' per ' you would get a label of 'kg per s'. Otherwise, a default of "/" will be used.

Using this project for large-scale engineering applications, I had a need for each level of complexity provided, so hopefully it's useful to others.

* Added BIDIMENSIONAL_SEPERATOR setting

Added BIDIMENSIONAL_SEPERATOR setting

* Corrected spelling of BIDIMENSIONAL_SEPARATOR

* Updated test_unicode_labels

Updated test_unicode_labels to reflect new bidimensional_separator functionality

* Corrected spelling of BIDIMENSIONAL_SEPARATOR

* Updated bidimensional_separator assertion

* Update forms.py

* Update forms.py

* Update forms.py

* Added bidimensional_seperator kwarg explanation

* Update forms.rst

* Update forms.rst

* Update forms.rst

* Added BIDIMENSIONAL_SEPERATOR setting to appconf

New conf.py file for Measurement

* Updated to use conf.py

Now uses conf.py to fetch BIDIMENSIONAL_SEPARATOR

* Added django-appconf

Added django-appconf>=1.0.2 for handling of app settings

* Added django-appconf

Added django-appconf>=1.0.2

* Flake tests and import updates

* whitespace cleanup for pep257

* whitespace cleanup for pep257
Permalink
Failed to load latest commit information.
django_measurement
docs
tests
.gitignore
.travis.yml Re-enable running tests; tests were disabled as part of a2017b7 for a… May 15, 2016
LICENSE
MANIFEST
MANIFEST.in
readme.rst
requirements-dev.txt
requirements.txt
setup.cfg Update QA Feb 11, 2016
setup.py

readme.rst

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.