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 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
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
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f473ead81a739dd7ddeb67d0ee1000c0444dfcc44353d56664d69934a96139e |
|
MD5 | 1f48ec7510f6f7f6e0e725ee342d5ca1 |
|
BLAKE2b-256 | fbb41243e6e7776ea84ced751a1f18066d4f621d45226af96011c6c79e2b0c7c |
File details
Details for the file django_denormalized-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: django_denormalized-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99a264000874d17ae5455c8736b0adb6fd63b32092353f53b709891973954fd3 |
|
MD5 | 7681a2347318e7e4690cdfd5be9efa4b |
|
BLAKE2b-256 | d2109df274d4bc7dd5b234233605b0d63b57c66b866897f6a45073ceb765fb24 |