{ "info": { "author": "Carlos Palol", "author_email": "carlos.palol@awarepixel.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.3", "Topic :: Software Development :: Libraries" ], "description": "\n\n==================\nDjango Money Field\n==================\n\n\nDjango model field for monetary amounts.\n\n\nInstallation\n============\n\n::\n\n pip install django-moneyfield\n\nMoneyfield requires:\n\n+ Python ==3.3\n+ Django ==1.5 (still working on 1.6 compatibility)\n+ `Money `_\n+ `Babel `_ (if you need currency formatting)\n\nBasic usage\n===========\n\n.. code:: python\n \n from django.db import Models\n from moneyfield import MoneyField\n \n class Book(models.Model):\n name = models.CharField(blank=True, max_length=100)\n price = MoneyField(decimal_places=2, max_digits=8)\n\nThe field ``price`` will be created in the database as two columns: ``price_amount``, and ``price_currency``. You may use any name ````, resulting in columns ``_amount`` and ``_currency``.\n\n.. code:: sql\n\n CREATE TABLE \"myapp_book\" (\n \"id\" integer NOT NULL PRIMARY KEY,\n \"name\" varchar(100) NOT NULL,\n \"price_amount\" decimal NOT NULL,\n \"price_currency\" varchar(3) NOT NULL\n );\n\nThe attribute ``price`` is only a convenience python descriptor that accepts and returns Money objects, and will be available only when working with a model instance.\n\n.. code:: python\n\n >>> book = Book.objects.get(id=1)\n >>> book.price\n USD 19.99\n >>> book.price = Money(\"9.99\", \"USD\")\n >>> book.save()\n >>> book.price\n USD 9.99\n\nFor any operation using Managers and QuerySets, the amount and the currency must be addressed separately, using ``price_amount`` and ``price_currency`` in this case. This allows for maximum flexibility and unambiguity.\n\n.. code:: python\n\n new_book = Book.objects.create(\n name=\"The new book\",\n price_amount=Decimal(\"29.99\"),\n price_currency=\"USD\"\n )\n \n books_in_usd = Book.objects.filter(price_currency=\"USD\")\n \n cheap_books = Book.objects.filter(price_amount__lt=Decimal('2'))\n \n cheap_books_eur = Book.objects.filter(\n price_amount__lt=Decimal('2'),\n price_currency=\"EUR\"\n )\n\n\nDefaults and choices\n--------------------\n\nYou can provide separate defaults for the amount and the currency as Decimal and the three letter currency code string, respectively:\n\n.. code:: python\n \n class Book(models.Model):\n name = models.CharField(blank=True, max_length=100)\n price = MoneyField(decimal_places=2, max_digits=8, \n amount_default=Decimal(\"0\"),\n currency_default=\"USD\")\n\n\nor a default Money value:\n\n.. code:: python\n \n class Book(models.Model):\n name = models.CharField(blank=True, max_length=100)\n price = MoneyField(decimal_places=2, max_digits=8, \n default=Money(\"0\", \"USD\"))\n\nYou can also set currency choices with ``currency_choices`` and a currency default with ``currency_default``:\n\n.. code:: python\n \n class Book(models.Model):\n CURRENCY_CHOICES = (\n ('EUR', 'EUR'),\n ('USD', 'USD')\n )\n CURRENCY_DEFAULT = 'EUR'\n \n name = models.CharField(blank=True, max_length=100)\n price = MoneyField(decimal_places=2, max_digits=8, \n currency_choices=CURRENCY_CHOICES,\n currency_default=CURRENCY_DEFAULT)\n\n\nFixed currency\n--------------\n\nIf you don't need to handle different currencies but want to benefit from using the Money class instead of just Decimals, you may want to set a fixed currency for your monetary field:\n\n.. code:: python\n\n class Book(models.Model):\n name = models.CharField(blank=True, max_length=100)\n price = MoneyField(decimal_places=2, max_digits=12, currency='USD')\n\nIn this case, the attribute ``price`` will only accept and return Money objects with currency \"USD\". **The database representation of this field will be** ``price_amount``, **with no currency column**. This is consistent with the multi-currency case, and allows for maximum flexibility while making schema migrations.\n\n\nMoneyField options\n==================\n\nMoneyField.max_digits\n Same as DecimalField: The maximum number of digits allowed in the number. Note that this number must be greater than or equal to ``decimal_places``.\n\nMoneyField.decimal_places\n Same as DecimalField: The number of decimal places to store with the number.\n\nMoneyField.currency\n Fixed currency for this field. This will omit the creation of a ``_currency`` column in the database.\n\nMoneyField.default\n Default Money value for this field (both amount and currency).\n\nMoneyField.currency_default\n Default currency value.\n\nMoneyField.amount_default\n Default amount value.\n\nMoneyField.currency_choices\n Regular Django choices iterable, e.g.::\n \n CURRENCY_CHOICES = (\n ('EUR', 'Euros'),\n ('USD', 'US Dollars')\n )\n\n\nForms\n=====\n\nA base model form class ``MoneyModelForm`` is included to show the monetary fields as just one field in forms, instead of separate amount and currency fields.\n\n.. code:: python\n\n from django.contrib import admin\n from moneyfield import MoneyModelForm\n from myapp.models import Book\n\n class BookAdmin(admin.ModelAdmin):\n list_display = ['id', 'name', 'price']\n form = MoneyModelForm\n \n admin.site.register(Book, BookAdmin)\n\n\nUsing ``MoneyModelForm`` is optional. You may also include it in the base classes of your custom model form class.\n\n\n\n.. figure:: https://raw.github.com/carlospalol/django-moneyfield/master/docs/static/img/form-choices.png\n \n **Using currency choices**\n\n.. figure:: https://raw.github.com/carlospalol/django-moneyfield/master/docs/static/img/form-fixed.png\n \n **Using fixed currency**\n\n.. figure:: https://raw.github.com/carlospalol/django-moneyfield/master/docs/static/img/form-free.png\n \n **Using free currency**\n\n\nContributions\n=============\n\nContributions are welcome. You can use the `regular github mechanisms `_.\n\nTo run the tests, sit on the package root (by setup.py) and run:\n\n::\n\n python tests/runtests.py\n\n\nLicense\n=======\n\ndjango-moneyfield is released under the **MIT license**, which can be found in the file ``LICENSE``.\n\n\n\n", "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/carlospalol/django-moneyfield", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "django-moneyfield", "package_url": "https://pypi.org/project/django-moneyfield/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-moneyfield/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/carlospalol/django-moneyfield" }, "release_url": "https://pypi.org/project/django-moneyfield/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "Django Money Model Field", "version": "0.2.1" }, "last_serial": 934809, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "132e12097db272d8d58e9bdb3d363970", "sha256": "793f0b2a0986435aa36a166edb54f682505a1383457a4d18483964e8121558fc" }, "downloads": -1, "filename": "django-moneyfield-0.2.tar.gz", "has_sig": false, "md5_digest": "132e12097db272d8d58e9bdb3d363970", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6601, "upload_time": "2013-11-25T14:40:20", "url": "https://files.pythonhosted.org/packages/ef/e5/afca457885e5d24418f87af426fd96020b3bf5f88980c3ff0a4e0aa3285a/django-moneyfield-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "104f2bcf8e782934594e61379b098fa9", "sha256": "72f129f573adc5d05a05cfbc4ba7b46fc76320dac510f6b4731ac243e76db484" }, "downloads": -1, "filename": "django-moneyfield-0.2.1.tar.gz", "has_sig": false, "md5_digest": "104f2bcf8e782934594e61379b098fa9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6639, "upload_time": "2013-12-03T16:00:45", "url": "https://files.pythonhosted.org/packages/aa/25/91c3dad4a7f05a94c858e04ca208026c0e4e1e90da013662602dfe1fbfa3/django-moneyfield-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "104f2bcf8e782934594e61379b098fa9", "sha256": "72f129f573adc5d05a05cfbc4ba7b46fc76320dac510f6b4731ac243e76db484" }, "downloads": -1, "filename": "django-moneyfield-0.2.1.tar.gz", "has_sig": false, "md5_digest": "104f2bcf8e782934594e61379b098fa9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6639, "upload_time": "2013-12-03T16:00:45", "url": "https://files.pythonhosted.org/packages/aa/25/91c3dad4a7f05a94c858e04ca208026c0e4e1e90da013662602dfe1fbfa3/django-moneyfield-0.2.1.tar.gz" } ] }