Skip to main content

This is a small Django utility module to allow you to correctly annotate or aggregate based on the sum of a Boolean field. This answers the question “how many objects do I have related to this object where foo is True.

Usage

Usage is pretty simple:

from django_boolean_sum import BooleanSum

MyModel.objects.annotate(priority_related_count=BooleanSum('related__priority'))

This will return instances of MyModel with a related_count attribute, which is the number of related instances which have priority=True.

Installation

From PyPI:

$ pip install django-boolean-sum

Caveats

This has been tested solely on PostgreSQL and Sqlite, using Django 1.4. It also depends on internal Django components which are not documented, and therefore are subject to possible breaking changes in future versions.

It is very naive about multi-databases, assuming that the query is being made for the backend of the default database.

Contributing

Pull Request it.

Release files for django-boolean-sum 0.2

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-boolean-sum 0.2
File Size Uploaded
django-boolean-sum-0.2.tar.gz 1.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-boolean-sum 0.2
File Interpreter ABI Platform
django_boolean_sum-0.2-py2-none-any.whl Python 2 none any Details

Total release size: 5.3 kB

Release files / django-boolean-sum-0.2.tar.gz

Download URL django-boolean-sum-0.2.tar.gz
Size 1.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2902c9d78d89519acdc3ab631d9a0a25cc7d563699dbbbbecb1af81456ab7db6
BLAKE2b-256 checksum
How to use checksums
566389e7987b4f498a17dc54dc17d67ab1db764e8a654369be75f5c0d2dbd88e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_boolean_sum-0.2-py2-none-any.whl

Download URL django_boolean_sum-0.2-py2-none-any.whl
Size 3.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
e71e1ed4c18f64ff6e5cffcfc17696f4829304f4565bcd69142f1da4071170ff
BLAKE2b-256 checksum
How to use checksums
82e6206a39d9f72afa0bd276bc3f5bdff20faee77b37450d3da7184f2788c3e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

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