django-bitfield

Software Screenshot:
django-bitfield
Software Details:
Version: 1.6.3
Upload Date: 14 Apr 15
Developer: Disqus
Distribution Type: Freeware
Downloads: 2

Rating: nan/5 (Total Votes: 0)

django-bitfield is a Django app that provides a BitField like class (using a BigIntegerField) for your Django models.

Installation

Install it with pip (or easy_install):

pip install django-bitfield

Usage

First you'll need to attach a BitField to your class. This acts as a BigIntegerField (BIGINT) in your database:

from bitfield import BitField

class MyModel(models.Model):
 flags = BitField(flags=(
 'awesome_flag',
 'flaggy_foo',
 'baz_bar',
 ))


Now you can use the field using very familiar Django operations:

# Create the model
o = MyModel.objects.create(flags=0)

# Add awesome_flag (does not work in SQLite)
MyModel.objects.filter(pk=o.pk).update(flags=MyModel.flags.awesome_flag)

# Set flags manually to [awesome_flag, flaggy_foo]
MyModel.objects.filter(pk=o.pk).update(flags=3)

# Remove awesome_flag (does not work in SQLite)
MyModel.objects.filter(pk=o.pk).update(flags=~MyModel.flags.awesome_flag)

# Test awesome_flag
if o.flags.awesome_flag:
 print "Happy times!"

# List all flags on the field
for f in o.flags:
 print f

Requirements:

  • Django
  • Python

Other Software of Developer Disqus

Comments to django-bitfield

Comments not found
Add Comment
Turn on images!