Skip to content

Provides an ExclusiveBooleanField which is a boolean (database) field where only one row in the table (or optionally, a subset of rows based on value of other fields) is True and all the other rows are False.

License

anentropic/django-exclusivebooleanfield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-exclusivebooleanfield

Build Status Latest PyPI version
Tested for: Python 2.6 Tested for: Python 2.7 Tested for: Python 3.4
Tested for: Django 1.3 Tested for: Django 1.4 Tested for: Django 1.5 Tested for: Django 1.6 Tested for: Django 1.7 Tested for: Django 1.8

Provides an ExclusiveBooleanField which is a boolean (db) field where only one row in the table (or optionally, a subset of table based on value of other fields) is True and all the other rows are False.

Usage:

from django.db import models

from exclusivebooleanfield.fields import ExclusiveBooleanField


class MyModel(models.Model):
    the_one = ExclusiveBooleanField()


class MyModel(models.Model):
    field_1 = ForeignKey()
    field_2 = CharField()
    the_one = ExclusiveBooleanField(on=('field_1', 'field_2'))
    # `on` is a bit like a unique constraint, value of field
    # is only exclusive for rows with same value of the on fields


class MyOtherModel(models.Model):
    field_1 = CharField()
    the_one = ExclusiveBooleanField(on='field_1')
    # if `on` is just a single field you don't have to wrap in a tuple

Tested on Django 1.3 thru 1.8, to run tests checkout the project and python setup.py test

About

Provides an ExclusiveBooleanField which is a boolean (database) field where only one row in the table (or optionally, a subset of rows based on value of other fields) is True and all the other rows are False.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages