{ "info": { "author": "AppointmentGuru", "author_email": "tech@appointmentguru.co", "bugtrack_url": null, "classifiers": [ "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# dj-querytools\n\nA collection of functions to make it a little easier to build aggregation SQL queries for Django projects\n\n## Installation\n\n```\npip install dj-querytools\n```\n\n## Usage\n\n### Simple aggregation:\n\nAssuming the following model:\n\n```\nclass Todo(models.Model):\n owner = models.CharField(max_length=30)\n title = models.CharField(max_length=30)\n status = models.CharField(max_length=30, choices=TODO_STATUSES)\n size = models.PositiveIntegerField(default=1)\n due = models.DateField()\n due_time = models.DateTimeField()\n```\n\n### `group_by_and_aggregate`\n\n**Example**\n\n```python\n\ngroup_by_and_aggregate(\n qs,\n 'size',\n 'Sum'\n)\n>> 20\n```\n\n### `group_by_and_annotate`\n\nPerforms the aggregation and groups by the provided field:\n\n**Example**\n\n```python\n\nresult = group_by_and_annotate(\n qs,\n 'status',\n 'Count'\n)\n>> {'D': 5, 'N': 1, 'P': 8}\n```\n\n### `as_timeseries`\n\n```\nqs = Todo.objects.filter(owner=\"Jack\")\nas_timeseries(\n qs,\n 'due_time',\n 'id',\n 'Count',\n '2018-11-01',\n '2018-11-10'\n)\n>> [{'x': '2018-11-01', 'y': 3.0}, {'x': '2018-11-02', 'y': 3.0}, {'x': '2018-11-03', 'y': 0}, {'x': '2018-11-04', 'y': 2.0}, {'x': '2018-11-05', 'y': 2.0}, {'x': '2018-11-06', 'y': 0}, {'x': '2018-11-07', 'y': 0}, {'x': '2018-11-08', 'y': 0}, {'x': '2018-11-09', 'y': 0}, {'x': '2018-11-10', 'y': 0}]\n```\n\n### `pivot_table`\n\nGiven a flat queryset, group it by one or more fields.\n\n* fields are comma seperated\n* optionally provide a serializer function to serialize items (otherwise it will just append the queryset row)\n\n```python\nresult = pivot_table(qs, 'owner,status', serialize_todo)\n\n>> {'Jack': {'N': [{'title': 'Day year outside whatever int'}], 'P': [{'title': 'Answer society close example '}, {'title': 'Raise real individual general'}], 'D': [{'title': 'Number organization particula'}, {'title': 'Least activity herself than c'}, {'title': 'Country local pretty yourself'}]}, 'Jane': {'P': [{'title': 'Prevent do still teacher grou'}, {'title': 'Include they management first'}, {'title': 'Number court few loss sort mu'}, {'title': 'That federal end local dream '}, {'title': 'Able ask listen. Cost ball me'}, {'title': 'Bad know meeting compare room'}], 'D': [{'title': 'Through town stay able car di'}, {'title': 'Tree design candidate because'}]}}\n```\n\n## periodic_breakdown\n\n`from querytools.tools import periodic_breakdown`\n\nProvide an aggregation broken down by a period (Trun(kind=)).\n\nSee: https://docs.djangoproject.com/en/2.1/ref/models/database-functions/#django.db.models.functions.TruncMonth\n\n**Defaults:**\n\n* `kind='month'`\n* `aggregate_field='ok'`\n* `aggregation = 'Count'`\n\n```python\n\n# simple case:\nresult = periodic_breakdown(qs, 'due')\n\n# slighly more fancy:\nresult = periodic_breakdown(\n qs,\n 'due',\n aggregate_field='size',\n aggregation = 'Sum'\n)\n```\n\n\n## Other stuff\n\n* For full functionality list, see `spec.txt`\n* For examples, check `example_app/tests.py`\n\n## Contributing\n\n**Update the spec:**\n\n```\npython manage.py test --testrunner=testreporter.runner.BDDTestRunner\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/SchoolOrchestration/libs/dj-querytools", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "dj-querytools", "package_url": "https://pypi.org/project/dj-querytools/", "platform": "", "project_url": "https://pypi.org/project/dj-querytools/", "project_urls": { "Homepage": "https://gitlab.com/SchoolOrchestration/libs/dj-querytools" }, "release_url": "https://pypi.org/project/dj-querytools/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Some utility functions to perform complex queries with the Django ORM", "version": "0.2.0" }, "last_serial": 5876574, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "512f62530f6ac7a2a839b2b5715bb10f", "sha256": "1795c95d43fa9f35c43bd7e9b5db3aec58cd679ef9190bea393f32f7eb3f1bf7" }, "downloads": -1, "filename": "dj-querytools-0.0.0.tar.gz", "has_sig": false, "md5_digest": "512f62530f6ac7a2a839b2b5715bb10f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2391, "upload_time": "2018-11-20T17:08:35", "url": "https://files.pythonhosted.org/packages/2a/9e/582524abb7bf390d7900dd3e714449d09fd758904e555d70d61a41eb3d2c/dj-querytools-0.0.0.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "e7daa6ebb15d75480fc5bcc175ad9b1f", "sha256": "c8f6be6d783c7e788ad2a70b72b5bc04a59c598804e78d5f8db963b1e8883bd4" }, "downloads": -1, "filename": "dj-querytools-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e7daa6ebb15d75480fc5bcc175ad9b1f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3504, "upload_time": "2018-11-20T17:43:27", "url": "https://files.pythonhosted.org/packages/a1/4b/442e38f84e45ccdb44126c02baa6d09de472a8638350f5897990fe371815/dj-querytools-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "37e2acafa81e0609bd95dd688ddba706", "sha256": "89419de83c77f6c3e6575c1cb9bb9e07541b926ffe9690871db0648358843335" }, "downloads": -1, "filename": "dj-querytools-0.2.0.tar.gz", "has_sig": false, "md5_digest": "37e2acafa81e0609bd95dd688ddba706", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3873, "upload_time": "2019-09-23T23:22:06", "url": "https://files.pythonhosted.org/packages/b6/37/ccc606284bde5e9b525f34de94c6d5cd82bef440cda65e9f4a7dffe11e88/dj-querytools-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "37e2acafa81e0609bd95dd688ddba706", "sha256": "89419de83c77f6c3e6575c1cb9bb9e07541b926ffe9690871db0648358843335" }, "downloads": -1, "filename": "dj-querytools-0.2.0.tar.gz", "has_sig": false, "md5_digest": "37e2acafa81e0609bd95dd688ddba706", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3873, "upload_time": "2019-09-23T23:22:06", "url": "https://files.pythonhosted.org/packages/b6/37/ccc606284bde5e9b525f34de94c6d5cd82bef440cda65e9f4a7dffe11e88/dj-querytools-0.2.0.tar.gz" } ] }