{ "info": { "author": "Tomas Peterka", "author_email": "prestizni@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "django-bit-category - freakin fast categories\n#############################################\n\n:author: Tomas Peterka\n:licence: GPL\n\nAbstract (and one concrete) ``Model`` with tree-like structure using bitwise ID field.\nThis implementation is **very simple** and **super fast**!\nGiven a category, you can query for related models (products) to the category\nand all it's subcategories by\n`SomeModel.objects.filter(category_id__gte=category.gte, category_id__lt=category.lt)`\n\nGet it\n======\n\nSource: https://github.com/katomaso/django-bit-category/\nPypi: https://pypi.python.org/pypi/django-bit-category/\n\nTechnical details\n=================\n\nThe key idea is to reserve a block of bits in model's ID for different levels of\nhierarchy. In the basic setup we expect 32 bit ID (can be changed via ``ID_BIT_WIDTH``)\nand we give 5 bits for each level (can be changed via ``LEVEL_BIT_WIDTH``).\nThe IDs looks like this::\n\n XXXXX000000000000000000000000000 # mask for the root category\n 00001000000000000000000000000000 # first root\n 00010000000000000000000000000000 # second root\n 00011000000000000000000000000000 # third root\n\n 00001000010000000000000000000000 # first child of the first root\n 00001000100000000000000000000000 # second child of the first root\n\n ...and so on\n\nGetting **all** descendants in all levels is in ``hierarchical_instance.descendants``,\nbut under the hood it is as simple as::\n\n SomeModel.objects.filter(category_id__gte=category.gte, category_id__lt=category.lt)\n\n\nWhat is included in this app\n----------------------------\n\n * abstract HierarchicalModel which takes care about the magic with IDs\n * abstract BaseCategory which contains the most usual category implementation\n * HierarchicalField which you can use for any custom model\n * HierarchicalWidget which dynamically (via AJAX) creates / deletes select boxes\n * urls.py and views.py which contains AJAX magic for form field working\n\n\nHow to make it work\n-------------------\n\nIf you just want to use just one of the abstract models then you don't need to do anything special.\nImport the abstract model ``from bitcategory.models import BaseCategory`` and inherit from it in your\nconcrete Model. Then make a foreign key in your another model which is going to use categories::\n\n # :file: models.py\n from django.db import models\n from bitcategory.models import BaseCategory\n\n class MyCategory(BaseCategory):\n # BaseCategory already provides fileds name, slug and path\n class Meta:\n abstract = False\n\n class MyProduct(models.Model):\n # some other fields like price, quantity ....\n category = models.ForeignKey('myproject.MyCategory', verbose_name=_(\"Category\"))\n\nThat is all to your ``Model`` definition. Now, provided you have a concrete instance of MyCategory in\nvariable ``category``, you can query products within the category and all its subcategories by::\n\n MyProduct.objects.filter(category_id__gte=category.gte, category_id__lt=category.lt)\n\nor to get products only for the category by::\n\n MyProduct.objects.filter(category=category)\n\nHowever, if you want to have the awesome dynamic select boxes in your forms with ``category`` in it,\nyou need to do more\n\n * add the ``bitcategory`` into your INSTALLED_APPS\n * add ``bitcategory.urls`` into your urls and specify your custom hierarchical\n model. If you didn't create your custom hierarchical model, then use our pre-built concrete model\n ``bitcategory.models.Category``. We do that in order to be able to respond to AJAX requests which are sent\n by the ``bitcategory.fields.HierarchicalField``. The most simple way looks like::\n\n # :file: urls.py\n from django.conf.urls import patterns, include, url\n from myapp.models import YourHierarchicalModel\n\n urlpatterns = patterns('',\n url('', include('bitcategory.urls'), {\"model\": YourHierarchicalModel}),\n )\n\nNow you are ready to show your form with categories in it. First, add\n``bitcategory.fields.HierarchicalField`` in the form. When rendering the form into a page, don't\nforget to include ``{{form.media}}`` into your template for javascripts.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/django-bit-category/", "keywords": "django category hierarchy", "license": "GPL v3", "maintainer": null, "maintainer_email": null, "name": "django-bit-category", "package_url": "https://pypi.org/project/django-bit-category/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-bit-category/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/django-bit-category/" }, "release_url": "https://pypi.org/project/django-bit-category/0.5.2/", "requires_dist": null, "requires_python": null, "summary": "Django category app with bitwise tree-like structure of primary key.", "version": "0.5.2" }, "last_serial": 2429478, "releases": { "0.2": [], "0.4": [ { "comment_text": "", "digests": { "md5": "08d80be38708308f0dc2606df966dc56", "sha256": "040a89b793ec2eca3143c5dc61c89a236e98b4268d912996d3164f366f05b7ac" }, "downloads": -1, "filename": "django-bit-category-0.4.tar.gz", "has_sig": false, "md5_digest": "08d80be38708308f0dc2606df966dc56", "packagetype": "bdist_wheel", "python_version": "any", "requires_python": null, "size": 7305, "upload_time": "2016-04-17T10:56:20", "url": "https://files.pythonhosted.org/packages/bb/b8/8ef4ab6ba111969091fb9b8ad911fa1d7731d2a15ca83ffd5b4728be3400/django-bit-category-0.4.tar.gz" } ], "0.5.2": [ { "comment_text": "", "digests": { "md5": "9e11cca596b544ccabf77b37674207b0", "sha256": "43828bac815250c6a93b1f369fcc914a76c570f0a929a8ca01014e7b85b63084" }, "downloads": -1, "filename": "django_bit_category-0.5.2-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "9e11cca596b544ccabf77b37674207b0", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 13571, "upload_time": "2016-10-28T20:01:07", "url": "https://files.pythonhosted.org/packages/a7/98/7b4b1f96e11f5adcf8c5890a33c20516eb6a9414fde706de3234b98c1cda/django_bit_category-0.5.2-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9e11cca596b544ccabf77b37674207b0", "sha256": "43828bac815250c6a93b1f369fcc914a76c570f0a929a8ca01014e7b85b63084" }, "downloads": -1, "filename": "django_bit_category-0.5.2-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "9e11cca596b544ccabf77b37674207b0", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 13571, "upload_time": "2016-10-28T20:01:07", "url": "https://files.pythonhosted.org/packages/a7/98/7b4b1f96e11f5adcf8c5890a33c20516eb6a9414fde706de3234b98c1cda/django_bit_category-0.5.2-py2.py3-none-any.whl" } ] }