Convenient fields and classes for handling measurements
Project description
Django Measurement
Easily use, manipulate, and store unit-aware measurement objects using Python and Django.
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(measurement=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 via Read the Docs.
Please post issues on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-measurement-3.0.0.tar.gz
.
File metadata
- Download URL: django-measurement-3.0.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a499b19d652235f1ec10c346cf0a5debe821e78a990cc595a4020778f0e85a6b |
|
MD5 | 1f2ce08932fcd0424a9dfa3c0b2ccdae |
|
BLAKE2b-256 | 9203a6b6b14d45fb274c47b9a29349e00d43fbe019ff5daf4095d77aade5fa3e |