bitfield_manager
Automatic bitfield management for Django Models.
Quickstart
Install bitfield_manager:
pip install django-bitfield-manager
Add it to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'bitfield_manager',
...
)
Usage
First you’ll need a parent model with a status field
from django.db import models
from bitfield_manager.models import ParentBitfieldModel, ChildBitfieldModelMixin
class ParentExample(ParentBitfieldModel):
status = models.BigIntegerField()
def __str__(self): # __unicode__ on Python 2
return "status: %i" % self.status
Then for all models you want django-bitfield-manager to manage add the BitfieldMeta with a list of parent models. The list of parent models takes in a tuple. The first field is the source that will be modified. The source should be a BigIntegerField or BitField (if using django-bitfield). The 2nd field is the bitflag to use (i.e. 0 will be 1 << 0, 1 will be 1 << 1, etc.)
class ChildExample1(ChildBitfieldModelMixin, models.Model):
parent = models.ForeignKey('ParentExample', null=True)
class BitfieldMeta:
parent_models = [('parent', 'status', 0)]
class ChildExample2(ChildBitfieldModelMixin, models.Model):
parent = models.ForeignKey('ParentExample', null=True)
class BitfieldMeta:
parent_models = [('parent.status', 1)]
Now when creating/deleting child models the parent status should update
# create the model
p = ParentExample.objects.create(status=0)
p2 = ParentExample.objects.create(status=0)
# add a child p.status is now 1
c1 = ChildExample1.objects.create(parent=p)
# add the other child. p.status is now 3
c2 = ChildExample2.objects.create(parent=p)
# deleting a child will refresh the status. p.status is now 2
c1.delete()
# updates or mass deletes will require manual refresh
# p.status will be 2 and p2.status will be 0
ChildExample2.objects.filter(parent=p).update(parent=p2)
# trigger a manual refresh. p.status is now correct with a status of 0
p.force_status_refresh()
# if you know the related models modified you can specify them
# p2.status is now 2
p2.force_status_refresh(related_models=[ChildExample2])
# force status refresh will work with models multiple levels deep. Specify the search_depth to search
# more than 1 level deep
p2.force_status_refresh(search_depth=2)
Features
Allows for automatic bitfield management for Django Models.
Will update the status when models are added or deleted
Supports multi-level relationships (use dot syntax)
Supports django-bitfield
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Credits
Tools used in rendering this package:
History
0.3.0 (2017-01-31)
Added example
Changed the parent_models models tuple from (‘parent’, ‘child’, 0) to (‘parent.child’, 0)
additional unit tests
bug fixes
0.2.0 (2017-01-27)
Added django-bitfield support
No longer uses signals
Added mixin for child models (ChildBitfieldModelMixin)
Added support for one-to-one and limited support for m2m fields
Added support for models multiple levels deep (using dot syntax)
0.1.0 (2017-01-18)
First release on PyPI.
Metadata
Release files for django-bitfield-manager 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-bitfield-manager-0.3.1.tar.gz | 7.6 kB | Without provenance | Details for django-bitfield-manager-0.3.1.tar.gz |
Release files / django-bitfield-manager-0.3.1.tar.gz
| Download URL | django-bitfield-manager-0.3.1.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95c43cd0a1734d4314ce0eaedf0a65622cf2d0e637293b34cc9bab32fcc6abe4
|
|
BLAKE2b-256 checksum How to use checksums |
bda2031cce9b682cf38f2e92d805a54bd24ad6c2660906f1da2f1941dcc7cd55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-bitfield-manager 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.