Skip to main content

Utils for maintaining denormalized aggregates for Django models

Project description


Utils for maintaining denormalized aggregates for Django models.

Build Status codecov PyPI version


from django.db import models
from src.denormalized import DenormalizedTracker, DenormalizedForeignKey

class Group(models.Model):
    members_count = models.PositiveIntegerField(default=0)
    points_sum = models.PositiveIntegerField(default=0)

class Member(models.Model):
    group = DenormalizedForeignKey(
        Group, models.CASCADE,
                # name of field to store denormalized count of active members
                # callback to determine whether object should be counted or not
                callback=lambda obj:,
                # QuerySet filter to count only suitable objects
                # multiple denormalized fields tracked for single foreign key
                # Sum/Min/Max is also supported
    active = models.BooleanField(default=True)
    points = models.IntegerField(default=0)

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_denormalized-1.0.0.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

django_denormalized-1.0.0-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