Skip to main content

Django complementary index definition and management.

Project description

Create triggers to do some aggregate and permit to count objects from database without using COUNT() aggregat.

Detailed documentation is in the “docs” directory.

Quick start

  1. Add “django_aggtrigg” to your INSTALLED_APPS setting like this:

  2. Import fields in your models:

    from django_aggtrigg.models import IntegerTriggerField
    from django_aggtrigg.models import FloatTriggerField
  3. Configure your fields as is:

    class Apple(models.Model):
        indice = IntegerTriggerField(default=0)
        mark = FloatTriggerField(default=0)

By default only the count aggregat will be created.

  1. Use the new manager on you Model

    objects = AggTriggManager()

Howto use the new aggregat

Instead of doing a COUNT as the traditionnal way:


you will do:


This is may be less easy, but so much more efficient when you manipulate billions or tuples in your relations.

What inside

The class apple was create in the app called foo so the default name of the table that contains data will be foo_apple, we use the tablename from the Model so if it’s changed in Meta will still be compliant.

A new table foo_apple__indice_agg is created in the same database as foo_apple, it will contain the aggregat:

foo=# \d foo_apple__indice_agg
Table "public.foo_apple__indice_agg"
  Column   |  Type   | Modifiers
 indice    | integer |
 agg_count | integer |
 agg_min   | integer |
    "foo_apple__indice_agg_indice_idx" btree (indice)

Project details

Download files

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

Files for django-aggtrigg, version 0.6.5
Filename, size File type Python version Upload date Hashes
Filename, size django-aggtrigg-0.6.5.tar.gz (16.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page