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 may be 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.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5af17d6d39dcaa19f1749cb04c6cbb235fe3c09f1cfdd5c4a0d644844a6b13e |
|
MD5 | 70188d22f9b7df2dd969286a03e188ec |
|
BLAKE2b-256 | d8d64863ee2448de2e4ee7f794abdce35d6a42bdf325cec554688f407eb11585 |