{ "info": { "author": "Robert Kajic", "author_email": "robert@kajic.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "====================\ndjango-counter-field\n====================\n\nIt is sometimes useful to cache the total number of objects associated with another object through a ForeignKey\nrelation. For example the total number of comments associated with an article.\n\ndjango-counter-field makes it easy to denormalize and keep such counters up to date.\n\nQuick start\n-----------\n\n1. Install django-counter-field::\n\n pip install django-counter-field\n\n2. Add \"django_counter_field\" to your INSTALLED_APPS setting::\n\n INSTALLED_APPS = (\n ...\n 'django_counter_field',\n )\n\n3. Add a CounterField to your model::\n\n from django_counter_field import CounterField\n\n\n class Article(models.Model):\n comment_count = CounterField()\n\n4. Add the CounterMixin to the related model::\n\n from django_counter_field import CounterMixin, connect_counter\n\n\n class Comment(CounterMixin, models.Model):\n article = models.ForeignKey(Article)\n\n5. Connect the related foreign key field with the counter field::\n\n connect_counter('comment_count', Comment.article)\n\nWhenever a comment is created the comment_count on the associated Article will be incremented. If the comment is\ndeleted, the comment_count will be automatically decremented.\n\n\nOverview\n--------\n\nCreating a new counter requires three simple steps:\n\n1. Add a `CounterField` field to the parent model.\n2. Add the `CounterMixin` mixin to the child model.\n3. Use `connect_counter` to connect the child model with the new counter.\n\nMost counters are simple in the sense that you want to count all child objects. Sometimes, however, objects should be\ncounted based on one or several conditions. For example you may not wish to count *all* comments on an article but\nonly comments that have been approved. You can create conditional counters by providing a third `is_in_counter_func`\nargument to `connect_counter`:\n\n connect_counter('comment_count', Comment.article, lambda comment: comment.is_approved)\n\nThe `is_in_counter_func` function will be called with `Comment` objects and must return `True` if the given comment\nshould be counted. It must not concern itself with checking if the comment is deleted or not, django-counter-field\ndoes that by default.\n\nBackfilling\n-----------\n\nOften you will add a `CounterField` to a model that already has a large number of associated objects. When a counter\nis created, it's value is initialized to zero. This value is likely incorrect. django-counter-field provides a couple\nof management commands that allow you to rebuild the value of a counter:\n\n1. List all available counters:\n\n $ python manage.py list_counters\n\n2. Rebuild a counter using one of the counter names given by `list_counters`:\n\n $ python manage.py rebuild_counter \n\nNote: The `rebuild_counter` management command will only update counters on objects that have at least one child\nobject. For example articles with at least one comment. Articles with no comments will not be updated. This\nis a conscious limitation; the use cases for such a feature seem very limited, if existent at all.\n\n\nDocumentation\n-------------\n\n $ pip install Sphinx\n $ cd docs\n $ make html\n Open build/html/index.html", "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/kajic/django-counter-field", "keywords": null, "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "django-counter-field", "package_url": "https://pypi.org/project/django-counter-field/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-counter-field/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/kajic/django-counter-field" }, "release_url": "https://pypi.org/project/django-counter-field/0.3.1/", "requires_dist": null, "requires_python": null, "summary": "django-counter-field makes it extremely easy to denormalize and keep track of related model counts.", "version": "0.3.1" }, "last_serial": 995515, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "9ee24689f71b833c708c435a5fd53c5a", "sha256": "bac57848e8bfa67c1fb31a6218ef9a10b770ded7c6076e0eaf28c72d05451140" }, "downloads": -1, "filename": "django-counter-field-0.1.tar.gz", "has_sig": false, "md5_digest": "9ee24689f71b833c708c435a5fd53c5a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12342, "upload_time": "2013-12-26T10:57:31", "url": "https://files.pythonhosted.org/packages/e3/25/cb2ad41a96a6aca0c83f2f4cd1cd761ce9430829b018e60de6ccf45fc4c2/django-counter-field-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "d86aaf69ab857b37e828052b533f4445", "sha256": "00b0bc4f6fa25d12437d192f093e0047b7f90f4fdf0524e84a93ee325f4683a7" }, "downloads": -1, "filename": "django-counter-field-0.2.tar.gz", "has_sig": false, "md5_digest": "d86aaf69ab857b37e828052b533f4445", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12312, "upload_time": "2013-12-27T08:29:50", "url": "https://files.pythonhosted.org/packages/a2/d9/4daf36bb02be7d9250b3ea41eb919554727d48da72c474684d72549c032f/django-counter-field-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "2b1fc8cb49919773cd4f88b935e1a198", "sha256": "ebfc858ea6b56bd3a7c028e5277ac9e2df6777de63708d667f1a7fdec0e6d1bf" }, "downloads": -1, "filename": "django-counter-field-0.3.tar.gz", "has_sig": false, "md5_digest": "2b1fc8cb49919773cd4f88b935e1a198", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13324, "upload_time": "2013-12-27T09:32:43", "url": "https://files.pythonhosted.org/packages/39/68/85741739aa3e1b5d6bb8f4b1565c7ea81442eb9da7efbbd3f1862b80f296/django-counter-field-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "23d17f96182dff55ae7264aed25c7e04", "sha256": "b95c6e60d749d18e4f8db63748429f10a9f0f1e5d7211b6fcc81621f8f0e7e9a" }, "downloads": -1, "filename": "django-counter-field-0.3.1.tar.gz", "has_sig": false, "md5_digest": "23d17f96182dff55ae7264aed25c7e04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13517, "upload_time": "2014-02-09T18:48:27", "url": "https://files.pythonhosted.org/packages/d9/9e/7466aadc059a4bcc27131e23b71b66530923f8217d19907ee681127dfbfb/django-counter-field-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "23d17f96182dff55ae7264aed25c7e04", "sha256": "b95c6e60d749d18e4f8db63748429f10a9f0f1e5d7211b6fcc81621f8f0e7e9a" }, "downloads": -1, "filename": "django-counter-field-0.3.1.tar.gz", "has_sig": false, "md5_digest": "23d17f96182dff55ae7264aed25c7e04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13517, "upload_time": "2014-02-09T18:48:27", "url": "https://files.pythonhosted.org/packages/d9/9e/7466aadc059a4bcc27131e23b71b66530923f8217d19907ee681127dfbfb/django-counter-field-0.3.1.tar.gz" } ] }