{"id":21179047,"url":"https://github.com/ocadotechnology/django-closuretree","last_synced_at":"2025-07-09T22:32:00.853Z","repository":{"id":25708208,"uuid":"29144908","full_name":"ocadotechnology/django-closuretree","owner":"ocadotechnology","description":"Efficient tree-based datastructure for Django","archived":false,"fork":false,"pushed_at":"2021-04-02T09:28:55.000Z","size":78,"stargazers_count":64,"open_issues_count":12,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-11T11:53:19.745Z","etag":null,"topics":["python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocadotechnology.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-12T16:33:09.000Z","updated_at":"2024-07-08T14:19:34.000Z","dependencies_parsed_at":"2022-08-24T14:13:01.156Z","dependency_job_id":null,"html_url":"https://github.com/ocadotechnology/django-closuretree","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocadotechnology%2Fdjango-closuretree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocadotechnology%2Fdjango-closuretree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocadotechnology%2Fdjango-closuretree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocadotechnology%2Fdjango-closuretree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocadotechnology","download_url":"https://codeload.github.com/ocadotechnology/django-closuretree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225600756,"owners_count":17494698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python"],"created_at":"2024-11-20T17:28:04.905Z","updated_at":"2024-11-20T17:28:05.640Z","avatar_url":"https://github.com/ocadotechnology.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"******************\ndjango-closuretree\n******************\n\n\n.. image:: https://travis-ci.org/ocadotechnology/django-closuretree.svg\n   :target: https://travis-ci.org/ocadotechnology/django-closuretree\n   :alt: Build Status\n.. image:: https://landscape.io/github/ocadotechnology/django-closuretree/master/landscape.svg?style=flat\n   :target: https://landscape.io/github/ocadotechnology/django-closuretree/master\n   :alt: Code Health Badge\n.. image:: https://readthedocs.org/projects/django-closuretree/badge/?version=latest\n   :target: http://django-closuretree.readthedocs.org/en/latest/\n   :alt: Documentation Status\n.. image:: https://coveralls.io/repos/ocadotechnology/django-closuretree/badge.svg\n   :target: https://coveralls.io/r/ocadotechnology/django-closuretree\n   :alt: Test Coverage\n.. image:: https://img.shields.io/pypi/v/django-closuretree.svg?style=flat\n   :target: https://pypi.python.org/pypi/django-closuretree/\n   :alt: Version Badge\n.. image:: https://img.shields.io/pypi/l/django-closuretree.svg?style=flat\n   :target: https://pypi.python.org/pypi/django-closuretree/\n   :alt: License Badge\n\n\n``django-closuretree`` is an implementation of the `closure tree \u003chttp://homepages.inf.ed.ac.uk/libkin/papers/tc-sql.pdf\u003e`_ technique for `Django \u003chttps://djangoproject.com\u003e`_ applications designed to provide efficient querying of `tree-based structures \u003chttp://en.wikipedia.org/wiki/Tree_%28data_structure%29\u003e`_ in a relational database. Its goal is to reduce the number of queries required when querying the children or parents of a given object.\n\nGiven the following model:\n\n.. code-block:: python\n\n    class Node(models.Model):\n        name = models.CharField(max_length=24)\n        parent = models.ForeignKey('self', related_name='children')\n\nThe children of each model can be queried with:\n\n.. code-block:: python\n\n    Node.objects.get(name='A').children.all()\n\nHowever, for recursive lookups, this results in a large number of queries. Instead, ``django-closuretree`` allows you to extract them all in one go:\n\n.. code-block:: python\n\n    from closuretree.models import ClosureModel\n\n    class Node(ClosureModel):\n        name = models.CharField(max_length=24)\n        parent = models.ForeignKey('self', related_name='children', null=True)\n\n    a = Node.objects.create(name='A')\n    Node.objects.create(name='B', parent=a)\n\n    Node.objects.get(name='A').get_descendants()\n\nA single query will obtain all the descendants.\n\n===========\nQuick Start\n===========\n\n* Install ``django-closuretree`` with ``pip install django-closuretree``.\n* Inherit your models from ``closuretree.models.ClosureModel`` instead of ``django.db.models.Model``.\n\nThat's it. You can now use ``get_descendants()`` and ``get_ancestors()`` on a model instance.\n\nIf you're adding this to an existing application that already has data in the database, you'll need to run the ``rebuildtable()`` method of each model before the closure tree will be populated with the existing data:\n\n.. code-block:: python\n\n    Node.rebuildtable()\n\n============\nContributing\n============\n\nTo contribute, fork the repo, do your work, and issue a pull request. We ask that contributors adhere to `PEP8 \u003chttps://www.python.org/dev/peps/pep-0008/\u003e`_ standards, and include full tests for all their code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focadotechnology%2Fdjango-closuretree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focadotechnology%2Fdjango-closuretree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focadotechnology%2Fdjango-closuretree/lists"}