Skip to main content
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.

Metadata

Release files for django-numfilters 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-numfilters 0.1.1
File Size Uploaded
django-numfilters-0.1.1.tar.gz 4.9 kB Details

Release files / django-numfilters-0.1.1.tar.gz

Download URL django-numfilters-0.1.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fe5971bd6238cf45ccc5e1f1f2b859da6c75ae4c3b6ab46112baaf424defa24b
BLAKE2b-256 checksum
How to use checksums
bbcf3c20971da0a20d4fa8e81096d44d7dc135f7605cddfd9072b20272946dbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.0.8

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page