{"id":15297389,"url":"https://github.com/goodmase/django-bitfield-manager","last_synced_at":"2026-01-05T20:39:32.946Z","repository":{"id":57419084,"uuid":"79587739","full_name":"goodmase/django-bitfield-manager","owner":"goodmase","description":"Automatic bitfield management for Django Models.","archived":false,"fork":false,"pushed_at":"2022-12-26T20:29:22.000Z","size":48,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T09:53:26.133Z","etag":null,"topics":["django","python","python2","python3"],"latest_commit_sha":null,"homepage":"https://django-bitfield-manager.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goodmase.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-20T18:53:33.000Z","updated_at":"2019-06-06T07:09:13.000Z","dependencies_parsed_at":"2023-01-31T01:15:23.789Z","dependency_job_id":null,"html_url":"https://github.com/goodmase/django-bitfield-manager","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodmase%2Fdjango-bitfield-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodmase%2Fdjango-bitfield-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodmase%2Fdjango-bitfield-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goodmase%2Fdjango-bitfield-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goodmase","download_url":"https://codeload.github.com/goodmase/django-bitfield-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245249189,"owners_count":20584497,"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":["django","python","python2","python3"],"created_at":"2024-09-30T19:17:01.812Z","updated_at":"2026-01-05T20:39:32.871Z","avatar_url":"https://github.com/goodmase.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=============================\nbitfield_manager\n=============================\n\n.. image:: https://badge.fury.io/py/django-bitfield-manager.svg\n    :target: https://badge.fury.io/py/django-bitfield-manager\n\n.. image:: https://travis-ci.org/goodmase/django-bitfield-manager.svg?branch=master\n    :target: https://travis-ci.org/goodmase/django-bitfield-manager\n\n.. image:: https://codecov.io/gh/goodmase/django-bitfield-manager/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/goodmase/django-bitfield-manager\n\n.. image:: https://readthedocs.org/projects/django-bitfield-manager/badge/?version=latest\n    :target: http://django-bitfield-manager.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\nAutomatic bitfield management for Django Models.\n\n\nQuickstart\n----------\n\nInstall bitfield_manager::\n\n    pip install django-bitfield-manager\n\nAdd it to your `INSTALLED_APPS`:\n\n.. code-block:: python\n\n    INSTALLED_APPS = (\n        ...\n        'bitfield_manager',\n        ...\n    )\n\n\nUsage\n--------\nFirst you'll need a parent model with a status field\n\n.. code-block:: python\n\n    from django.db import models\n    from bitfield_manager.models import ParentBitfieldModel, ChildBitfieldModelMixin\n\n\n    class ParentExample(ParentBitfieldModel):\n        status = models.BigIntegerField()\n\n    def __str__(self):  # __unicode__ on Python 2\n        return \"status: %i\" % self.status\n\nThen for all models you want django-bitfield-manager to manage add the BitfieldMeta with a list of parent models.\nThe list of parent models takes in a tuple. The first field is the source that will be modified. The\nsource should be a BigIntegerField or BitField (if using django-bitfield). The 2nd field\nis the bitflag to use (i.e. 0 will be 1 \u003c\u003c 0, 1 will be 1 \u003c\u003c 1, etc.)\n\n.. code-block:: python\n\n    class ChildExample1(ChildBitfieldModelMixin, models.Model):\n        parent = models.ForeignKey('ParentExample', null=True)\n\n        class BitfieldMeta:\n            parent_models = [('parent', 'status', 0)]\n\n    class ChildExample2(ChildBitfieldModelMixin, models.Model):\n        parent = models.ForeignKey('ParentExample', null=True)\n\n        class BitfieldMeta:\n            parent_models = [('parent.status', 1)]\n\nNow when creating/deleting child models the parent status should update\n\n.. code-block:: python\n\n    # create the model\n    p = ParentExample.objects.create(status=0)\n    p2 = ParentExample.objects.create(status=0)\n    # add a child p.status is now 1\n    c1 = ChildExample1.objects.create(parent=p)\n\n    # add the other child. p.status is now 3\n    c2 = ChildExample2.objects.create(parent=p)\n\n    # deleting a child will refresh the status. p.status is now 2\n    c1.delete()\n\n    # updates or mass deletes will require manual refresh\n    # p.status will be 2 and p2.status will be 0\n    ChildExample2.objects.filter(parent=p).update(parent=p2)\n\n    # trigger a manual refresh. p.status is now correct with a status of 0\n    p.force_status_refresh()\n\n    # if you know the related models modified you can specify them\n    # p2.status is now 2\n    p2.force_status_refresh(related_models=[ChildExample2])\n\n    # force status refresh will work with models multiple levels deep. Specify the search_depth to search\n    # more than 1 level deep\n    p2.force_status_refresh(search_depth=2)\n\nDjango Bitfield Example\n--------\n\n.. code-block:: python\n\n    from django.db import models\n    from bitfield_manager.models import ParentBitfieldModelMixin, ChildBitfieldModelMixin\n    from bitfield import BitField\n\n\n    class Person(ParentBitfieldModelMixin, models.Model):\n        name = models.CharField(max_length=255)\n        status = BitField(flags=(\n            ('has_children', 'Has Children'),\n            ('has_a_home', 'Has a Home'),\n            ('has_a_car', 'Has a car')\n        ))\n\n        def __str__(self):\n            return \"NAME: %s STATUS: %s\" % (self.name, \",\".join([str(s) for s in self.status]))\n\n\n    class Car(ChildBitfieldModelMixin, models.Model):\n        make = models.CharField(max_length=255)\n        model = models.CharField(max_length=255)\n        owner = models.ForeignKey('Person')\n\n        class BitfieldMeta:\n            parent_models = [('owner.status', Person.status.has_a_car)]\n\n\n    class Child(ChildBitfieldModelMixin, models.Model):\n        name = models.CharField(max_length=255)\n        parent = models.ForeignKey('Person')\n\n        class BitfieldMeta:\n            parent_models = [('parent.status', Person.status.has_children)]\n\n\n    class Home(ChildBitfieldModelMixin, models.Model):\n        owner = models.ForeignKey('Person')\n\n        class BitfieldMeta:\n            parent_models = [('owner.status', Person.status.has_a_home)]\n\nFeatures\n--------\n\n* Allows for automatic bitfield management for Django Models.\n* Will update the status when models are added or deleted\n* Supports multi-level relationships (use dot syntax)\n* Supports django-bitfield\n\nRunning Tests\n-------------\n\nDoes the code actually work?\n\n::\n\n    source \u003cYOURVIRTUALENV\u003e/bin/activate\n    (myenv) $ pip install tox\n    (myenv) $ tox\n\nCredits\n-------\n\nTools used in rendering this package:\n\n*  Cookiecutter_\n*  `cookiecutter-djangopackage`_\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`cookiecutter-djangopackage`: https://github.com/pydanny/cookiecutter-djangopackage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmase%2Fdjango-bitfield-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodmase%2Fdjango-bitfield-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmase%2Fdjango-bitfield-manager/lists"}