Skip to main content

Mathematical template filters for Django

Project description

https://travis-ci.org/amatellanes/django-numfilters.svg?branch=master https://coveralls.io/repos/amatellanes/django-numfilters/badge.png?branch=master Pypi version Pypi downloads

django-numfilters is a collection of template filters for Django who provides access to several basic mathematical functions.

Download

To install it by using pip:

$ pip install django-numfilters

or by using easy_install:

$ easy_install django-numfilters

You can also pot for installing it from source:

$ git clone git@github.com:amatellanes/django-numfilters.git
$ cd django-numfilters
$ python setup.py install

Installation

To enable django-numfilters in your Django project, you need to add django_numfilters to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_numfilters',
    ...
)

Usage

This section provides a summary of django-numfilters features.

Firstly, you need make filters available to your templates using {% load numfilters %} tag. After this, you can use next tags:

abs

Returns the absolute value of a, for a number.

add

This filter is provided by Django.

sub

Returns a - b, for a and b numbers.

mul

Returns a * b, for a and b numbers.

div

Returns a / b, for a and b numbers (classic division).

mod

Returns a % b, for a and b numbers.

floordiv

Returns a // b, for a and b numbers.

pow

Returns a ** b, for a and b numbers.

sqrt

Return the square root of a, for a number.

Example

{% load numfilters %}
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Example django-numfilters</title>
</head>
<body>
<ul>

    <li>abs(-41) = {{ -41|abs }}</li>

    <li>23 - 7 = {{ 23|sub:7 }}</li>

    <li>25 * 2 = {{ 25|mul:2 }}</li>

    <li>32 / 4 = {{ 32|div:4 }}</li>

    {% with a=15 b=3 %}
        <li>15 % 3 = {{ a|mod:b }}</li>
    {% endwith %}

    {% with a=5 b=2 %}
        <li>5 // 2 = {{ a|floordiv:b }}</li>
    {% endwith %}

    <li>pow(5, 2) = {{ 5|pow:2 }}</li>

    {% with a=64 %}
        <li>sqrt(64) = {{ a|sqrt }}</li>
    {% endwith %}

</ul>
</body>
</html>

Testing

You can see the current Travis CI build here: https://travis-ci.org/amatellanes/django-numfilters.

Changelog

Release 0.1.1 (no codename, released on December 26th 2014)

  • Fix minor bugs.

Release 0.1.0 (no codename, released on July 20th 2014)

  • Initial release.

License

MIT License, see LICENSE file.

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-numfilters-0.1.1.tar.gz (4.9 kB view hashes)

Uploaded Source

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