Utils for maintaining denormalized aggregates for Django models
Project description
django-denormalized
Utils for maintaining denormalized aggregates for Django models.
Example
from django.db import models
from 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 is also supported
aggregate=models.Sum("points"))
])
active = models.BooleanField(default=True)
points = models.IntegerField(default=0)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django_denormalized-0.8.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27f98fe7a8da038676fff3f0de15d359251ec0babd98c68e2af6989f43c4b0d2 |
|
MD5 | ddf6d36cabc3e8cedaebfb720d992f27 |
|
BLAKE2b-256 | 5d6a42e02c990b10b6d9a494a6dbf7e921e60c38d46f6d3630d2c6d5469544d0 |