Skip to main content

A Django app to make simple calculations in your django forms

Project description

django-calculation

Release PyPI version PyPI - Django Version PyPI - Python Version

Make simple calculations in your django forms.

chrome-capture

Installation

pip install django-calculation

Add calculation to your INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'calculation',
]

Usage

Import calculation and complete the definition like this. The widget NumericCalculationInput expects the calculation definition as the first argument.

from django import forms

import calculation


class TestForm(forms.Form):
    quantity = forms.DecimalField()
    price = forms.DecimalField()
    amount = forms.DecimalField(
        widget=calculation.NumericCalculationInput(
            {
                'mode': calculation.FORMULA,
                'formula': 'quantity*price'    
            },
            attrs = {'disabled': True}
        )
    )
    tax = forms.DecimalField(
        widget=calculation.NumericCalculationInput(
            {
                'mode': calculation.FORMULA,
                'formula': 'parseFloat(amount/11).toFixed(2)'    
            },
            attrs = {'disabled': True}
        )
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-calculation-0.0.6.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

django_calculation-0.0.6-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page