{ "info": { "author": "Henrique Bastos", "author_email": "henrique@bastos.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Database", "Topic :: Software Development :: Libraries" ], "description": "Django Aggregate If: Condition aggregates for Django\r\n====================================================\r\n\r\n.. image:: https://travis-ci.org/henriquebastos/django-aggregate-if.png?branch=master\r\n :target: https://travis-ci.org/henriquebastos/django-aggregate-if\r\n :alt: Test Status\r\n\r\n.. image:: https://landscape.io/github/henriquebastos/django-aggregate-if/master/landscape.png\r\n :target: https://landscape.io/github/henriquebastos/django-aggregate-if/master\r\n :alt: Code Helth\r\n\r\n.. image:: https://pypip.in/v/django-aggregate-if/badge.png\r\n :target: https://crate.io/packages/django-aggregate-if/\r\n :alt: Latest PyPI version\r\n\r\n.. image:: https://pypip.in/d/django-aggregate-if/badge.png\r\n :target: https://crate.io/packages/django-aggregate-if/\r\n :alt: Number of PyPI downloads\r\n\r\n*Aggregate-if* adds conditional aggregates to Django.\r\n\r\nConditional aggregates can help you reduce the ammount of queries to obtain\r\naggregated information, like statistics for example.\r\n\r\nImagine you have a model ``Offer`` like this one:\r\n\r\n.. code-block:: python\r\n\r\n class Offer(models.Model):\r\n sponsor = models.ForeignKey(User)\r\n price = models.DecimalField(max_digits=9, decimal_places=2)\r\n status = models.CharField(max_length=30)\r\n expire_at = models.DateField(null=True, blank=True)\r\n created_at = models.DateTimeField(auto_now_add=True)\r\n updated_at = models.DateTimeField(auto_now=True)\r\n\r\n OPEN = \"OPEN\"\r\n REVOKED = \"REVOKED\"\r\n PAID = \"PAID\"\r\n\r\nLet's say you want to know:\r\n\r\n#. How many offers exists in total;\r\n#. How many of them are OPEN, REVOKED or PAID;\r\n#. How much money was offered in total;\r\n#. How much money is in OPEN, REVOKED and PAID offers;\r\n\r\nTo get these informations, you could query:\r\n\r\n.. code-block:: python\r\n\r\n from django.db.models import Count, Sum\r\n\r\n Offer.objects.count()\r\n Offer.objects.filter(status=Offer.OPEN).aggregate(Count('pk'))\r\n Offer.objects.filter(status=Offer.REVOKED).aggregate(Count('pk'))\r\n Offer.objects.filter(status=Offer.PAID).aggregate(Count('pk'))\r\n Offer.objects.aggregate(Sum('price'))\r\n Offer.objects.filter(status=Offer.OPEN).aggregate(Sum('price'))\r\n Offer.objects.filter(status=Offer.REVOKED).aggregate(Sum('price'))\r\n Offer.objects.filter(status=Offer.PAID).aggregate(Sum('price'))\r\n\r\nIn this case, **8 queries** were needed to retrieve the desired information.\r\n\r\nWith conditional aggregates you can get it all with only **1 query**:\r\n\r\n.. code-block:: python\r\n\r\n from django.db.models import Q\r\n from aggregate_if import Count, Sum\r\n\r\n Offer.objects.aggregate(\r\n pk__count=Count('pk'),\r\n pk__open__count=Count('pk', only=Q(status=Offer.OPEN)),\r\n pk__revoked__count=Count('pk', only=Q(status=Offer.REVOKED)),\r\n pk__paid__count=Count('pk', only=Q(status=Offer.PAID)),\r\n pk__sum=Sum('price'),\r\n pk__open__sum=Sum('price', only=Q(status=Offer.OPEN)),\r\n pk__revoked__sum=Sum('price'), only=Q(status=Offer.REVOKED)),\r\n pk__paid__sum=Sum('price'), only=Q(status=Offer.PAID))\r\n )\r\n\r\nInstallation\r\n------------\r\n\r\n*Aggregate-if* works with Django 1.4, 1.5, 1.6 and 1.7.\r\n\r\nTo install it, simply:\r\n\r\n.. code-block:: bash\r\n\r\n $ pip install django-aggregate-if\r\n\r\nInspiration\r\n-----------\r\n\r\nThere is a 5 years old `ticket 11305`_ that will (*hopefully*) implement this feature into\r\nDjango 1.8.\r\n\r\nUsing Django 1.6, I still wanted to avoid creating custom queries for very simple\r\nconditional aggregations. So I've cherry picked those ideas and others from the\r\ninternet and built this library.\r\n\r\nThis library uses the same API and tests proposed on `ticket 11305`_, so when the\r\nnew feature is available you can easily replace ``django-aggregate-if``.\r\n\r\nLimitations\r\n-----------\r\n\r\nConditions involving joins with aliases are not supported yet. If you want to\r\nhelp adding this feature, you're welcome to check the `first issue`_.\r\n\r\nContributors\r\n------------\r\n\r\n* `Henrique Bastos `_\r\n* `Iuri de Silvio `_\r\n* `Hampus Stjernhav `_\r\n* `Bradley Martsberger `_\r\n* `Markus Bertheau `_\r\n* `end0 `_\r\n* `Scott Sexton `_\r\n* `Mauler `_\r\n* `trbs `_\r\n\r\nChangelog\r\n---------\r\n\r\n0.5\r\n - Support for Django 1.7\r\n\r\n0.4\r\n - Use tox to run tests.\r\n - Add support for Django 1.6.\r\n - Add support for Python3.\r\n - The ``only`` parameter now freely supports joins independent of the main query.\r\n - Adds support for alias relabeling permitting excludes and updates with aggregates filtered on remote foreign key relations.\r\n\r\n0.3.1\r\n - Fix quotation escaping.\r\n - Fix boolean casts on Postgres.\r\n\r\n0.2\r\n - Fix postgres issue with LIKE conditions.\r\n\r\n0.1\r\n - Initial release.\r\n\r\n\r\nLicense\r\n=======\r\n\r\nThe MIT License.\r\n\r\n.. _ticket 11305: https://code.djangoproject.com/ticket/11305\r\n.. _first issue: https://github.com/henriquebastos/django-aggregate-if/issues/1", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/henriquebastos/django-aggregate-if/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-aggregate-if", "package_url": "https://pypi.org/project/django-aggregate-if/", "platform": "any", "project_url": "https://pypi.org/project/django-aggregate-if/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/henriquebastos/django-aggregate-if/" }, "release_url": "https://pypi.org/project/django-aggregate-if/0.5/", "requires_dist": null, "requires_python": null, "summary": "Conditional aggregates for Django, just like the famous SumIf in Excel.", "version": "0.5" }, "last_serial": 1312102, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "5f9cc67d694cbdeb027a83ad12ef50ff", "sha256": "13e76e6a33d72e0a0a182173dd073ce04d3cc70b19453c111fdfd76d0545fa35" }, "downloads": -1, "filename": "django-aggregate-if-0.1.tar.gz", "has_sig": false, "md5_digest": "5f9cc67d694cbdeb027a83ad12ef50ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3708, "upload_time": "2012-12-28T01:54:22", "url": "https://files.pythonhosted.org/packages/4f/fb/2abb24b84ce341451695766c47ee17fb41bc9cb32e6fce7b4a02394411c5/django-aggregate-if-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "000cd0d78391f0ffb38dcbae63c14abe", "sha256": "7836285fe0b698cdd71e23a61acba85402067a736ee32352cde7ee4e66137a0b" }, "downloads": -1, "filename": "django-aggregate-if-0.2.tar.gz", "has_sig": false, "md5_digest": "000cd0d78391f0ffb38dcbae63c14abe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3791, "upload_time": "2012-12-29T20:05:34", "url": "https://files.pythonhosted.org/packages/1e/e7/8208b6ebd2468a8db88f8c0fc23a77f7f75fd812d3936fee58b7d1d9e987/django-aggregate-if-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "9a9510c0aaa962a856bdb882abb0d177", "sha256": "0806705d533a6d684b7533779b28490c8a72f3e37c2f5dd040e862f60b7b7d9d" }, "downloads": -1, "filename": "django-aggregate-if-0.3.tar.gz", "has_sig": false, "md5_digest": "9a9510c0aaa962a856bdb882abb0d177", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3783, "upload_time": "2013-01-11T00:15:45", "url": "https://files.pythonhosted.org/packages/c5/9f/e9c56b8f84211f031adf0072212501fd3d9d4b344c162a3d1d5d80a51736/django-aggregate-if-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "92f49d0d40eccbd5101a25807841ce0d", "sha256": "207e04bc738342761ac1079098655944acd38dd831eb567e5a0c93efb43ecd0c" }, "downloads": -1, "filename": "django-aggregate-if-0.3.1.tar.gz", "has_sig": false, "md5_digest": "92f49d0d40eccbd5101a25807841ce0d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3815, "upload_time": "2013-01-11T02:09:48", "url": "https://files.pythonhosted.org/packages/d0/14/433867c7e90f63cfb6dc51089755b913df37a0eed289eebd55b95063d02a/django-aggregate-if-0.3.1.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "7f8cf13e6050f5e503d5933a1085939e", "sha256": "8d8d2e976053d7a8a401bb6a506ec6c8710caece95c8a43c25a460e42e65f1b6" }, "downloads": -1, "filename": "django-aggregate-if-0.4.tar.gz", "has_sig": false, "md5_digest": "7f8cf13e6050f5e503d5933a1085939e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4822, "upload_time": "2014-03-24T02:00:16", "url": "https://files.pythonhosted.org/packages/46/cd/19b8dfa9cb98053cbd4d8629f7ece52e50d59900940a58e79739861b12e0/django-aggregate-if-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "88f8c8874a1c73748a9fce1e232ff94f", "sha256": "ae2f991c5faf7d48068b6a16ee7649ff333d77d06c8d14d143d5ba67420acf3c" }, "downloads": -1, "filename": "django-aggregate-if-0.5.tar.gz", "has_sig": false, "md5_digest": "88f8c8874a1c73748a9fce1e232ff94f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5122, "upload_time": "2014-11-18T22:38:15", "url": "https://files.pythonhosted.org/packages/39/b5/1eb6e244add6ed4caf09797bb6bd1a82b07bcfc940251ec98a9e6639ad7c/django-aggregate-if-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "88f8c8874a1c73748a9fce1e232ff94f", "sha256": "ae2f991c5faf7d48068b6a16ee7649ff333d77d06c8d14d143d5ba67420acf3c" }, "downloads": -1, "filename": "django-aggregate-if-0.5.tar.gz", "has_sig": false, "md5_digest": "88f8c8874a1c73748a9fce1e232ff94f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5122, "upload_time": "2014-11-18T22:38:15", "url": "https://files.pythonhosted.org/packages/39/b5/1eb6e244add6ed4caf09797bb6bd1a82b07bcfc940251ec98a9e6639ad7c/django-aggregate-if-0.5.tar.gz" } ] }