Giter VIP home page Giter VIP logo

django-prices's Introduction

django-prices: Django fields for the prices module

Build Status codecov.io

Provides support for models:

from django.db import models

from django_prices.models import PriceField

class Product(models.Model):
    name = models.CharField('Name')
    price = PriceField('Price', currency='BTC', max_digits=12, decimal_places=2)

And forms:

from django import forms

from django_prices.forms import PriceField

class ProductForm(forms.Form):
    name = forms.CharField(label='Name')
    price = PriceField(label='Price', currency='BTC')

And templates:

{% load prices %}

<p>Price: {% gross foo.price %} ({% net foo.price %} + {% tax foo.price %} tax)</p>

Note: for template tags to work, you need to add django_prices to your INSTALLED_APPS.

You can also install the wonderful babel library and get proper currency symbols with prices_i18n. First install BabelDjango:

$ pip install BabelDjango

Then follow the instruction to add it to your INSTALLED_APPS and MIDDLEWARE_CLASSES. Finally load the localized template tags:

{% load prices_i18n %}

<p>Price: {% gross foo.price %} ({% net foo.price %} + {% tax foo.price %} tax)</p>

You can also use HTML output from prices_i18n template tags, they will wrap currency symbol in a <span> element:

{% load prices_i18n %}

<p>Price: {% gross foo.price html=True %} ({% net foo.price html=True %} + {% tax foo.price html=True %} tax)</p>

It will be rendered as a following structure (for example with English locale):

<span class="currency">$</span>15.00

Batteries included: django-prices comes with South migration support.

django-prices's People

Contributors

artursmet avatar bharathwaaj avatar bogdal avatar derenio avatar gregmuellegger avatar maarcingebala avatar marekbrzoska avatar mitcom avatar mkalinowski avatar mociepka avatar patrys avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.