{ "info": { "author": "Ionel Cristian M\u0103rie\u0219", "author_email": "contact@ionelmc.ro", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: Microsoft :: Windows", "Operating System :: OS Independent", "Operating System :: POSIX", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP", "Topic :: Utilities" ], "description": "========\nOverview\n========\n\n\n\nSimple and generic model related data prefetch framework for Django solving the \"1+N queries\" problem that happens when\nyou need related data for your objects.\n\nIn most of the cases you'll have forward relations (foreign keys to something)\nand can use select_related to fetch that data on the same query. However, in\nsome cases you cannot design your models that way and need data from reverse\nrelations (models that have foreign keys to your objects).\n\nDjango has prefetch_related_ for this, however, this framework provides greater\nflexibility than Django's prefetch_related_ queryset method at the cost\nof writting the mapping and query functions for the data. This has the advantage\nthat you can do things prefetch_related_ cannot (see the latest_book example_\nbellow).\n\n* Free software: BSD license\n\n.. _prefetch_related: https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related\n\nInstallation guide\n==================\n\nInstall it::\n\n pip install django-prefetch\n\nUse it as your model's default manager (or as a base class if you have custom\nmanager).\n\nRequirements\n============\n\n:OS: Any\n:Runtime: Python 2.7, 3.3+ or PyPy\n:Packages: Django>=1.9\n\nExample\n=======\n\nHere's a simple example of models and prefetch setup::\n\n from django.db import models\n from prefetch import PrefetchManager, Prefetcher\n\n class Author(models.Model):\n name = models.CharField(max_length=100)\n\n objects = PrefetchManager(\n books = Prefetcher(\n filter = lambda ids: Book.objects.filter(author__in=ids),\n reverse_mapper = lambda book: [book.author_id],\n decorator = lambda author, books=(): setattr(author, 'books', books)\n ),\n latest_book = Prefetcher(\n filter = lambda ids: Book.objects.filter(author__in=ids),\n reverse_mapper = lambda book: [book.author_id],\n decorator = lambda author, books=(): setattr(\n author,\n 'latest_book',\n max(books, key=lambda book: book.created)\n )\n )\n )\n\n class Book(models.Model):\n class Meta:\n get_latest_by = 'created'\n\n name = models.CharField(max_length=100)\n created = models.DateTimeField(auto_now_add=True)\n author = models.ForeignKey(Author)\n\nUse it like this::\n\n for a in Author.objects.prefetch('books', 'latest_book'):\n print a.books\n print a.latest_book\n\nPrefetcher arguments\n--------------------\n\nExample models::\n\n class LatestNBooks(Prefetcher):\n def __init__(self, count=2):\n self.count = count\n\n def filter(self, ids):\n return Book.objects.filter(author__in=ids)\n\n def reverse_mapper(self, book):\n return [book.author_id]\n\n def decorator(self, author, books=()):\n books = sorted(books, key=lambda book: book.created, reverse=True)\n setattr(author,\n 'latest_%s_books' % self.count,\n books[:self.count])\n\n class Author(models.Model):\n name = models.CharField(max_length=100)\n\n objects = PrefetchManager(\n latest_n_books = LatestNBooks\n )\n\n\nUse it like this::\n\n from prefetch import P\n\n for a in Author.objects.prefetch(P('latest_n_books', count=5)):\n print a.latest_5_book\n\n.. note::\n\n ``P`` is optional and you can only use for prefetch definitions that are Prefetcher subclasses. You can't use it with prefetcher-instance style\n definitions like in the first example. Don't worry, if you do, you will get an exception explaining what's wrong.\n\n\nOther examples\n--------------\n\nCheck out the tests for more examples.\n\nTODO\n====\n\n* Document ``collect`` option of ``Prefetcher``\n* Create tests covering custom ``collect`` and ``mapper``\n\n\nChangelog\n=========\n\n1.2.1 (2018-09-04)\n------------------\n\n* Fixed missing entry in changelog.\n\n1.2.0 (2018-09-04)\n------------------\n\n* Added support for Django 1.11, dropped support for Django <1.9. Contributed by Martin Bachwerk in\n `#16 `_.\n\n1.1.0 (2016-02-20)\n------------------\n\n* Fixed a test assertion. Contributed by George Ma in `#12 `_.\n* Added support for Django 1.9. Contributed by Will Stott in `#14 `_.\n* Fixed use of deprecated `field.rel.to` momdel API (Django 1.9+).\n\n1.0.1 (2015-09-05)\n------------------\n\n* Fixed manager type check. Contributed by George Ma in `#11 `_.\n\n1.0.0 (2014-12-05)\n------------------\n\n* Fixed issues with ``select_related`` being removed when prefetch is used (`#9 `_).\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ionelmc/django-prefetch", "keywords": "", "license": "BSD 2-Clause License", "maintainer": "", "maintainer_email": "", "name": "django-prefetch", "package_url": "https://pypi.org/project/django-prefetch/", "platform": "", "project_url": "https://pypi.org/project/django-prefetch/", "project_urls": { "Homepage": "https://github.com/ionelmc/django-prefetch" }, "release_url": "https://pypi.org/project/django-prefetch/1.2.1/", "requires_dist": [ "Django (>=1.9)" ], "requires_python": "", "summary": "Simple and generic model related data prefetch framework for Django solving the \"1+N queries\" problem that happens when you need related data for your objects.", "version": "1.2.1" }, "last_serial": 4238558, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "c881627b72a92f535375ec02d8b69ef1", "sha256": "eae0bd7fdde3c485672645b1d78ddb56a634752da8ef0724f31303845531abdd" }, "downloads": -1, "filename": "django-prefetch-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c881627b72a92f535375ec02d8b69ef1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3047, "upload_time": "2012-02-07T23:51:50", "url": "https://files.pythonhosted.org/packages/17/b4/7cd66fae9c8077692ac8eec3696f279f6c7c4852c45ea6a04909b5c9cebe/django-prefetch-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "c9807933678946a34e3a1b7552ef7d65", "sha256": "85ec6f327cdd6499b846738b490cf6b365c68c94cb147907c3fb2b43c660498a" }, "downloads": -1, "filename": "django-prefetch-0.1.1.tar.gz", "has_sig": false, "md5_digest": "c9807933678946a34e3a1b7552ef7d65", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5505, "upload_time": "2012-02-08T02:33:29", "url": "https://files.pythonhosted.org/packages/3b/2b/ef167dc916ff5ae03e34a9577d4f4bd7f8a506308611b591431f3c48edb8/django-prefetch-0.1.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "b69ee238f5c1d607e20a13a05e8ffa60", "sha256": "031a664790db37debb866637971138d7d16136f5d689e860a3110c26f5db2e91" }, "downloads": -1, "filename": "django-prefetch-0.2.tar.gz", "has_sig": false, "md5_digest": "b69ee238f5c1d607e20a13a05e8ffa60", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12433, "upload_time": "2014-02-01T20:08:37", "url": "https://files.pythonhosted.org/packages/3f/c3/a9c135e60bfc38041f3d1916533189963cc49db61b8ec9058340f6564f0d/django-prefetch-0.2.tar.gz" } ], "0.2.0": [], "1.0.0": [ { "comment_text": "", "digests": { "md5": "5ee49fcc35f7ca718fd2a5ba22aa3d20", "sha256": "faefc559b8a564da737d43542fb04d85a820d4735bd023dd4b1f6c3ce3ec4c99" }, "downloads": -1, "filename": "django_prefetch-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5ee49fcc35f7ca718fd2a5ba22aa3d20", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8266, "upload_time": "2014-12-05T10:40:41", "url": "https://files.pythonhosted.org/packages/0d/25/3f17a86d8ef75596b2d37ec3b64716cf0c6e5c75275786885d5853d7c7b7/django_prefetch-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0e3668f17bde4cc4df6cc9774338f7ea", "sha256": "761b3021206f2f034cf8874261d4396933b15d490c60707f57708b6faf2ab99b" }, "downloads": -1, "filename": "django-prefetch-1.0.0.tar.gz", "has_sig": false, "md5_digest": "0e3668f17bde4cc4df6cc9774338f7ea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15926, "upload_time": "2014-12-05T10:40:39", "url": "https://files.pythonhosted.org/packages/3a/91/4d778981eb8bb46ea0975ccb768dcddfcb3c332128710ab9966b7929b665/django-prefetch-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "99c6a9c22b3b5787000a9859036be783", "sha256": "469a402086a35f43c3b83b7ff1dcafabe90f0a0d8343b079d70ba2ae34d4b62d" }, "downloads": -1, "filename": "django_prefetch-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "99c6a9c22b3b5787000a9859036be783", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8867, "upload_time": "2015-09-05T16:31:35", "url": "https://files.pythonhosted.org/packages/d7/8f/d187384952288446d4c698ed88eb0344865c4b3318381413e796fd990543/django_prefetch-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "06b7d396222f339b25c94e2fb6c87c33", "sha256": "77ba37754ecf34b6d819a53a1a014504b4cbb8ac1393f35a6d26d9521f8c113c" }, "downloads": -1, "filename": "django-prefetch-1.0.1.tar.gz", "has_sig": false, "md5_digest": "06b7d396222f339b25c94e2fb6c87c33", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22242, "upload_time": "2015-09-05T16:31:58", "url": "https://files.pythonhosted.org/packages/a6/6c/b1f74ff8864da41b206b90d14124f1b1f26fb7333186d0c2983926d642aa/django-prefetch-1.0.1.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "41b0221276922f47d093b3ebd318e3d4", "sha256": "de914c667a29d7740aa0ec968241d1254c8190b9893a79483ba9aba59e94dd01" }, "downloads": -1, "filename": "django_prefetch-1.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "41b0221276922f47d093b3ebd318e3d4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8594, "upload_time": "2016-02-20T18:07:28", "url": "https://files.pythonhosted.org/packages/75/b8/32ee86da277f62999a30b9dfc4dd85abae6ae32667da9ad6c416d5290c8a/django_prefetch-1.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7e4f4ae9429aa5cea5f52eadab7829b4", "sha256": "0402d37b79bf3f009011473b3ba181456cacdbe748347435a78198217e9fd803" }, "downloads": -1, "filename": "django-prefetch-1.1.0.tar.gz", "has_sig": false, "md5_digest": "7e4f4ae9429aa5cea5f52eadab7829b4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25374, "upload_time": "2016-02-20T18:07:35", "url": "https://files.pythonhosted.org/packages/e7/87/ba282c76ce68346a3d88a735a75df91f00844736b895d2b0b8f6a3025d6d/django-prefetch-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "6e3a03232de955d405c9bdcead79b9e6", "sha256": "144466030a6df3532b1a5d01b1936a47feadb2bf6edf162cd6734234df7165ea" }, "downloads": -1, "filename": "django_prefetch-1.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6e3a03232de955d405c9bdcead79b9e6", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5692, "upload_time": "2018-09-04T17:42:56", "url": "https://files.pythonhosted.org/packages/45/b7/1f1dcf3d757711ec7cd5c66a67f420aee7fe79f0b768e8f086a6dd36cb02/django_prefetch-1.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "44516ca824879f4dc2f310fe5ae93fd7", "sha256": "0cb4c74740d0249cdfb7fecb4224636a99e47018f4fa7ed3e209ea585ff61118" }, "downloads": -1, "filename": "django-prefetch-1.2.0.tar.gz", "has_sig": false, "md5_digest": "44516ca824879f4dc2f310fe5ae93fd7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18680, "upload_time": "2018-09-04T17:42:57", "url": "https://files.pythonhosted.org/packages/db/c2/8386bc9ba7bfc0f9e05c87c38631f14c133fb0943aa0018259a6017acfb6/django-prefetch-1.2.0.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "319e43e9a61ce637918d6c819294206e", "sha256": "f284104930750f0c6883c2f5153fbc24cd3f7ff5788936a04e8d05b4e1994c2e" }, "downloads": -1, "filename": "django_prefetch-1.2.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "319e43e9a61ce637918d6c819294206e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5757, "upload_time": "2018-09-04T17:48:41", "url": "https://files.pythonhosted.org/packages/b5/da/8a940fd5e220c0a105c05ae20811b7062bedd75a332882d2521270b83831/django_prefetch-1.2.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "adacce5c9ae0a9bded1fcd053e797297", "sha256": "9106d2c4ee0336d741441505af5088a9981153896167c8262b3f72ae99c7c617" }, "downloads": -1, "filename": "django-prefetch-1.2.1.tar.gz", "has_sig": false, "md5_digest": "adacce5c9ae0a9bded1fcd053e797297", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20317, "upload_time": "2018-09-04T17:48:43", "url": "https://files.pythonhosted.org/packages/43/2c/fd9ccb0137137f49d5b935f639ff2193a4a25290c1ba9080d2f609430381/django-prefetch-1.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "319e43e9a61ce637918d6c819294206e", "sha256": "f284104930750f0c6883c2f5153fbc24cd3f7ff5788936a04e8d05b4e1994c2e" }, "downloads": -1, "filename": "django_prefetch-1.2.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "319e43e9a61ce637918d6c819294206e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5757, "upload_time": "2018-09-04T17:48:41", "url": "https://files.pythonhosted.org/packages/b5/da/8a940fd5e220c0a105c05ae20811b7062bedd75a332882d2521270b83831/django_prefetch-1.2.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "adacce5c9ae0a9bded1fcd053e797297", "sha256": "9106d2c4ee0336d741441505af5088a9981153896167c8262b3f72ae99c7c617" }, "downloads": -1, "filename": "django-prefetch-1.2.1.tar.gz", "has_sig": false, "md5_digest": "adacce5c9ae0a9bded1fcd053e797297", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20317, "upload_time": "2018-09-04T17:48:43", "url": "https://files.pythonhosted.org/packages/43/2c/fd9ccb0137137f49d5b935f639ff2193a4a25290c1ba9080d2f609430381/django-prefetch-1.2.1.tar.gz" } ] }