Fork of Django that allows you to use Postgres's array_accum function. It adds function ArrayAccum in django.db.models. Using ArrayAccum will only work on Postgresql.
Project description
Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. This fork (pkg name Django-ArrayAccum on pypi) allows you to use the array_accum function available in Postgresql. This function will NOT work in other databases. If you are happy with Postgresql and want to be able to use the array_accum within Django (and not write custom sql) this fork is for you to try.
This fork was created from Django-1.5 dev version from the master branch. Will try to keep it up-to-date with django master. Feel free to remind me if it gets behind.
This fork just modifies two files.
django/db/models/aggregates.py
django/db/models/sql/aggregates.py
This adds a function called ArrayAccum which you can then use in any query involving aggregations (similar to Sum, Avg etc which are built-in).
Example Usage: Suppose you have a model defined as such:
class People(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
And lets say you want to show the most common last names, count, associated first names — then here is how you can do it:
from django.db.models import Count, ArrayAccum
results = People.objects.values("last_name").annotate(count=Count('id'),
unique_first_names=ArrayAccum("first_name", distinct=True)).order_by('-count')
Everything else is standard Django stuff version 1.5+. Django documentation is in the “docs” directory and online at http://docs.djangoproject.com/en/dev/.
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
File details
Details for the file Django-ArrayAccum-1.0.tar.gz.
File metadata
- Download URL: Django-ArrayAccum-1.0.tar.gz
- Upload date:
- Size: 7.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dde2bb3e208e7c03070c26ebe9366ffe6820a196431bf051e95daf3528806c57
|
|
| MD5 |
2443c36d55f950271a186998cc54eb95
|
|
| BLAKE2b-256 |
44dfa032692a5f9eb3d44fd904d07de18475dba9a8c6d2b256323d9c0017391d
|