{"id":13502711,"url":"https://github.com/mirumee/django-prices","last_synced_at":"2025-04-04T13:12:35.739Z","repository":{"id":5281642,"uuid":"6460913","full_name":"mirumee/django-prices","owner":"mirumee","description":"Django fields for the prices module","archived":false,"fork":false,"pushed_at":"2024-04-02T19:34:30.000Z","size":216,"stargazers_count":158,"open_issues_count":21,"forks_count":53,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-28T12:07:35.047Z","etag":null,"topics":["currencies","currency","django","money","price","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mirumee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-10-30T16:53:12.000Z","updated_at":"2025-02-11T21:31:35.000Z","dependencies_parsed_at":"2024-01-18T23:22:55.838Z","dependency_job_id":"0c190fd9-9fab-4234-a299-3f9df13633b1","html_url":"https://github.com/mirumee/django-prices","commit_stats":{"total_commits":253,"total_committers":24,"mean_commits":"10.541666666666666","dds":0.6719367588932806,"last_synced_commit":"d0a8652865c9eb7f571e7259727815b391a8ef4e"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirumee%2Fdjango-prices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirumee%2Fdjango-prices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirumee%2Fdjango-prices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirumee%2Fdjango-prices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mirumee","download_url":"https://codeload.github.com/mirumee/django-prices/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182353,"owners_count":20897380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["currencies","currency","django","money","price","python"],"created_at":"2024-07-31T22:02:23.057Z","updated_at":"2025-04-04T13:12:35.717Z","avatar_url":"https://github.com/mirumee.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"django-prices: Django fields for the `prices` module\n====================================================\n\n[![Build Status](https://secure.travis-ci.org/mirumee/django-prices.png)](https://travis-ci.org/mirumee/django-prices) [![codecov.io](https://img.shields.io/codecov/c/github/mirumee/django-prices/master.svg)](http://codecov.io/github/mirumee/django-prices?branch=master)\n\n# Installation\n\n* `pip install django-prices`\n* Add `django_prices` to your `INSTALLED_APPS` at `settings.py`\n* Follow `enmerkar` [instructions](https://github.com/Zegocover/enmerkar#using-the-middleware) and update both your `INSTALLED_APPS` and `MIDDLEWARE_CLASSES`.\n\n# Features\n\nProvides support for models:\n\n```python\nfrom django.db import models\nfrom django_prices.models import MoneyField, TaxedMoneyField\n\n\nclass Model(models.Model):\n    currency = models.CharField(max_length=3, default=\"BTC\")\n    price_net_amount = models.DecimalField(max_digits=9, decimal_places=2, default=\"5\")\n    price_net = MoneyField(amount_field=\"price_net_amount\", currency_field=\"currency\")\n    price_gross_amount = models.DecimalField(\n        max_digits=9, decimal_places=2, default=\"5\"\n    )\n    price_gross = MoneyField(\n        amount_field=\"price_gross_amount\", currency_field=\"currency\"\n    )\n    price = TaxedMoneyField(\n        net_amount_field=\"price_net_amount\",\n        gross_amount_field=\"price_gross_amount\",\n        currency=\"currency\",\n    )\n```\n\nAnd forms:\n\n```python\nfrom django import forms\n\nfrom django_prices.forms import MoneyField\n\nAVAILABLE_CURRENCIES = [\"BTC\", \"USD\"]\n\n\nclass ProductForm(forms.Form):\n    name = forms.CharField(label=\"Name\")\n    price_net = MoneyField(label=\"net\", available_currencies=AVAILABLE_CURRENCIES)\n```\n\nAnd validators:\n\n```python\nfrom django import forms\nfrom prices.forms import Money\n\nfrom django_prices.forms import MoneyField\nfrom django_prices.validators import (\n    MaxMoneyValidator, MinMoneyValidator, MoneyPrecisionValidator)\n\n\nclass DonateForm(forms.Form):\n    donator_name = forms.CharField(label=\"Your name\")\n    donation = MoneyField(\n        label=\"net\",\n        available_currencies=[\"BTC\", \"USD\"],\n        max_digits=9,\n        decimal_places=2,\n        validators=[\n            MoneyPrecisionValidator(),\n            MinMoneyValidator(Money(5, \"USD\")),\n            MaxMoneyValidator(Money(500, \"USD\")),\n        ],\n    )\n```\n\nIt also provides support for templates:\n\n```html+django\n{% load prices %}\n\n\u003cp\u003ePrice: {{ foo.price.gross|amount }} ({{ foo.price.net|amount }} + {{ foo.price.tax|amount }} tax)\u003c/p\u003e\n```\n\n\nYou can also use HTML output from `prices` template tags, they will wrap currency symbol in a `\u003cspan\u003e` element:\n\n```html+django\n{% load prices %}\n\n\u003cp\u003ePrice: {{ foo.price.gross|amount:'html' }} ({{ foo.price.net|amount:'html' }} + {{ foo.price.tax|amount:'html' }} tax)\u003c/p\u003e\n```\n\nIt will be rendered as a following structure (for example with English locale):\n\n```html\n\u003cspan class=\"currency\"\u003e$\u003c/span\u003e15.00\n```\n\n## How to migrate to django-prices 2.0\n\nVersion 2.0 introduces major changes to how prices data is stored in models, enabling setting price's currency per model instance.\n\nSteps to migrate:\n\n1. In your **forms**:\n    * remove the `currency` argument\n    * add `available_currencies` with available choices.\n\n    If the form specified `MoneyFields` in `fields` option, replace those with explicit declarations instead:\n\n    ```python\n    AVAILABLE_CURRENCIES = [(\"BTC\", \"bitcoins\"), (\"USD\", \"US dollar\")]\n\n    class ModelForm(forms.ModelForm):\n        class Meta:\n            model = models.Model\n            fields = []\n\n        price_net = MoneyField(available_currencies=AVAILABLE_CURRENCIES)\n    ```\n\n1. In your **models** using `MoneyField`:\n    * Replace all occurrences of the `MoneyField` class with `DecimalField`\n    * Remove the `currency` argument from them\n    * Change `default` from Money instance to value acceptable by Decimal field\n\n        Example of code:\n        ```python\n        price_net = MoneyField(\n            \"net\", currency=\"BTC\", default=Money(\"5\", \"BTC\"), max_digits=9, decimal_places=2\n        )\n        ```\n        Updated code:\n        ```python\n        price_net = models.DecimalField(\"net\", default=\"5\", max_digits=9, decimal_places=2)\n        ```\n\n1. In your **migration** files:\n    * Replace all occurrences of the `MoneyField` class with `DecimalField`\n    * Remove the `currency` argument from them\n    * Change `default` from Money instance to value acceptable by Decimal field\n\n        ```python\n        field = django_prices.models.MoneyField(currency='BTC', decimal_places=2, default='5', max_digits=9, verbose_name='net')\n        ```\n        Updated code:\n        ```python\n        field = models.DecimalField(decimal_places=2, default='5', max_digits=9, verbose_name='net')\n        ```\n\n1. Rename fields in **models**. Your old field will still store amount of money, so probably the best choice would be `price_net_amount` instead `price_net`.\n\n1. All places which use Models and it's fields can prevent django app from even starting the code. Possible issues: code tries to access non existing fields. Exclude those fields for now from your ModelForms, Graphene types etc.\n\n1. Run `python manage.py makemigrations`. Make sure to do this step before adding new `MoneyFields` to model! If not, django will generate `delete/create` migrations instead of `rename`.\n\n1. Run `python manage.py migrate`.\n\n1. Update `django-prices`.\n\n1. Add `models.CharField` for currency and `MoneyField` to your models:\n\n    ```python\n    currency = models.CharField(max_length=3, default=\"BTC\")\n    price_net_amount = models.DecimalField(\"net\", default=\"5\", max_digits=9, decimal_places=2)\n    price_net = MoneyField(amount_field=\"price_net_amount\", currency_field=\"currency\")\n    ```\n\n1. Run `python manage.py makemigrations` and `python manage.py migrate`.\n\n1. Change `TaxedMoneyField` declaration:\n\n    ```python\n    price = TaxedMoneyField(\n        net_amount_field=\"price_net_amount\",\n        gross_amount_field=\"price_gross_amount\",\n        currency=\"currency\",\n    )\n    ```\n\n1. Remember to address changes in previously edited ModelForms\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirumee%2Fdjango-prices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmirumee%2Fdjango-prices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirumee%2Fdjango-prices/lists"}