{ "info": { "author": "Ben Harling", "author_email": "blrharling@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: Unix", "Programming Language :: Python" ], "description": "[![Build Status](https://travis-ci.org/bharling/django-pint.svg?branch=master)](https://travis-ci.org/bharling/django-pint)\n[![Coverage Status](https://coveralls.io/repos/github/bharling/django-pint/badge.svg?branch=master)](https://coveralls.io/github/bharling/django-pint?branch=master)\n[![PyPI](https://img.shields.io/pypi/dm/django-pint.svg?maxAge=2592000?style=plastic)]()\n[![PyPI](https://img.shields.io/pypi/v/django-ping.svg?maxAge=2592000?style=plastic)]()\n\nDjango Quantity Field\n================\n\nA Small django field extension allowing you to store quantities in certain units and perform conversions easily. Uses [pint](https://github.com/hgrecco/pint) behind the scenes. Also contains a form field class and form widget that allows a user to choose alternative units to input data. The cleaned_data will output the value in the base_units defined for the field, eg: you specify you want to store a value in grams but will allow users to input either grams or ounces.\n\nCompatibility\n-------------\n\nRequires django >= 1.8, and python 2.7/3.2/3.3/3.4\n\nInstallation\n------------\n\n pip install django-pint\n\n\nSimple Example\n-----------------------\nBest way to illustrate is with an example\n\n # app/models.py\n \n from django.db import models\n from quantityfield.fields import QuantityField\n \n class HayBale(models.Model):\n\t weight = QuantityField('tonne')\n\nQuantities are stored and retrieved like any other field\n\n >> bale = HayBale.objects.create(weight=1.2)\n >> bale = HayBale.objects.first()\n\t>> bale.weight\n\t\n\t>> bale.weight.magnitude\n\t1.2\n\t>> bale.weight.units\n\t'tonne'\n\t>> bale.weight.to('kilogram')\n\t\n\t>> bale.weight.to('pound')\n\t\n\nYou can also pass Quantity objects to be stored in models. These are automatically converted to the units defined for the field ( but can be converted to something else when retrieved of course ).\n\n >> from quantityfield import ureg\n >> Quantity = ureg.Quantity\n >> pounds = Quantity(500 * ureg.pound)\n >> bale = HayBale.objects.create(weight=pounds)\n >> bale.weight\n \n\nUse the inbuilt form field and widget to allow input of quantity values in different units\n\n from quantityfield.fields import QuantityFormField\n\n class HayBaleForm(forms.Form):\n weight = QuantityFormField(base_units='gram', unit_choices=['gram', 'ounce', 'milligram'])\n\nThe form will render a float input and a select widget to choose the units. Whenever cleaned_data is presented from the above form the weight field value will be a Quantity with the units set to grams ( values are converted from the units input by the user ).\n\nFor comparative lookups, query values will be coerced into the correct units when comparing values, this means that comparing 1 ounce to 1 tonne should yield the correct results.\n\n less_than_a_tonne = HayBale.objects.filter(weight__lt=Quantity(2000 * ureg.pound))", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bharling/django-pint", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "django-pint", "package_url": "https://pypi.org/project/django-pint/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-pint/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/bharling/django-pint" }, "release_url": "https://pypi.org/project/django-pint/0.4/", "requires_dist": null, "requires_python": null, "summary": "Quantity Field for Django using pint library for automated unit conversions", "version": "0.4" }, "last_serial": 2560030, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "e1641760d96bd497d1f3b8591f1f39f4", "sha256": "d7db22d90692cd0c9e17bf53e2fdab5c0cc128b27cccf69d2d7d75b32da1c0f5" }, "downloads": -1, "filename": "django-pint-0.2.tar.gz", "has_sig": false, "md5_digest": "e1641760d96bd497d1f3b8591f1f39f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5099, "upload_time": "2016-09-13T10:28:44", "url": "https://files.pythonhosted.org/packages/af/32/212942d25bc9dfa3ea8860484420fbafc47e1da47aae6729d605b2f350e9/django-pint-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "98f6a305afe23839efb40592cc26ff9d", "sha256": "1270d40b6b113f631191cbbde20958f2f23ff11a747d2f25f63bf0bb33ffa57f" }, "downloads": -1, "filename": "django-pint-0.3.tar.gz", "has_sig": false, "md5_digest": "98f6a305afe23839efb40592cc26ff9d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5304, "upload_time": "2016-10-06T11:32:37", "url": "https://files.pythonhosted.org/packages/56/7f/9f7483efd37abeee36628601d77623ad01ab2a9a3c44986f0d369ad199e3/django-pint-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "d9d2f89eb3748b12fd76c24728bc9982", "sha256": "098f68f8376d7935e30812e7c9910394c6b70ea16211fb5f26c923909abaf3e5" }, "downloads": -1, "filename": "django-pint-0.4.zip", "has_sig": false, "md5_digest": "d9d2f89eb3748b12fd76c24728bc9982", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11035, "upload_time": "2017-01-08T00:50:29", "url": "https://files.pythonhosted.org/packages/a2/e3/f8963082808e2e04cc0d05a82824fe2d118b3e0fd63535c817ad0c1bbb03/django-pint-0.4.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d9d2f89eb3748b12fd76c24728bc9982", "sha256": "098f68f8376d7935e30812e7c9910394c6b70ea16211fb5f26c923909abaf3e5" }, "downloads": -1, "filename": "django-pint-0.4.zip", "has_sig": false, "md5_digest": "d9d2f89eb3748b12fd76c24728bc9982", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11035, "upload_time": "2017-01-08T00:50:29", "url": "https://files.pythonhosted.org/packages/a2/e3/f8963082808e2e04cc0d05a82824fe2d118b3e0fd63535c817ad0c1bbb03/django-pint-0.4.zip" } ] }