Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anentropic/django-exclusivebooleanfield
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.
https://github.com/anentropic/django-exclusivebooleanfield
Last synced: 24 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/anentropic/django-exclusivebooleanfield
- Owner: anentropic
- License: mit
- Created: 2014-04-14T13:48:24.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-28T15:01:07.000Z (over 8 years ago)
- Last Synced: 2024-11-09T21:43:34.314Z (about 1 month ago)
- Language: Python
- Homepage:
- Size: 41 KB
- Stars: 24
- Watchers: 1
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - django-exclusivebooleanfield - 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. (Python)
README
django-exclusivebooleanfield
============================[![Build Status](https://travis-ci.org/anentropic/django-exclusivebooleanfield.svg?branch=master)](https://travis-ci.org/anentropic/django-exclusivebooleanfield)
[![Latest PyPI version](https://badge.fury.io/py/django-exclusivebooleanfield.svg)](https://pypi.python.org/pypi/django-exclusivebooleanfield/)
![Tested for: Python 2.6](https://img.shields.io/badge/Python%202.6--brightgreen.svg)
![Tested for: Python 2.7](https://img.shields.io/badge/Python%202.7--brightgreen.svg)
![Tested for: Python 3.4](https://img.shields.io/badge/Python%203.4--brightgreen.svg)
![Tested for: Django 1.3](https://img.shields.io/badge/Django%201.3--brightgreen.svg)
![Tested for: Django 1.4](https://img.shields.io/badge/Django%201.4--brightgreen.svg)
![Tested for: Django 1.5](https://img.shields.io/badge/Django%201.5--brightgreen.svg)
![Tested for: Django 1.6](https://img.shields.io/badge/Django%201.6--brightgreen.svg)
![Tested for: Django 1.7](https://img.shields.io/badge/Django%201.7--brightgreen.svg)
![Tested for: Django 1.8](https://img.shields.io/badge/Django%201.8--brightgreen.svg)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:
```python
from django.db import modelsfrom 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 fieldsclass 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`