Skip to main content

Utils for maintaining denormalized aggregates for Django models

Project description

django-denormalized

Utils for maintaining denormalized aggregates for Django models.

Build Status codecov PyPI version

Example

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,
        trackers=[
            DenormalizedTracker(
                # name of field to store denormalized count of active members
                "members_count",
                # callback to determine whether object should be counted or not
                callback=lambda obj: obj.active,
                # QuerySet filter to count only suitable objects
                query=models.Q(active=True)),
            DenormalizedTracker(
                # multiple denormalized fields tracked for single foreign key
                "points_sum",
                # Sum/Min/Max is also supported
                aggregate=models.Sum("points"))
        ])
    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 details)

Uploaded Source

Built Distribution

django_denormalized-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file django_denormalized-1.0.0.tar.gz.

File metadata

  • Download URL: django_denormalized-1.0.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for django_denormalized-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7f473ead81a739dd7ddeb67d0ee1000c0444dfcc44353d56664d69934a96139e
MD5 1f48ec7510f6f7f6e0e725ee342d5ca1
BLAKE2b-256 fbb41243e6e7776ea84ced751a1f18066d4f621d45226af96011c6c79e2b0c7c

See more details on using hashes here.

File details

Details for the file django_denormalized-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_denormalized-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99a264000874d17ae5455c8736b0adb6fd63b32092353f53b709891973954fd3
MD5 7681a2347318e7e4690cdfd5be9efa4b
BLAKE2b-256 d2109df274d4bc7dd5b234233605b0d63b57c66b866897f6a45073ceb765fb24

See more details on using hashes here.

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