Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Choices on steroids

Project Description
choose
========

Choices on steroids

.. image:: https://img.shields.io/pypi/v/choose.svg
:target: https://pypi.python.org/pypi/choose

.. image:: https://img.shields.io/travis/ulamlabs/choose.svg
:target: https://travis-ci.org/ulamlabs/choose

.. image:: https://codecov.io/gh/ulamlabs/choose/branch/master/graph/badge.svg
:target: https://codecov.io/gh/ulamlabs/choose


Supported versions
================

- Python 2 and 3 support


How to install
==========

.. code-block:: bash

pip install choose


Basic usage:
===========

.. code-block:: python

>>> class Types(choose.Choices):
>>> BAR = choose.Choice('foo_bar', 'Foo Bar')
>>> BAZ = choose.Choice('foo_baz', 'Foo Baz')
>>> Types.BAR
'foo_bar'
>>> Types.BAR.text
'Foo Bar'
>>> Types.items()
(('foo_bar', 'Foo Bar'), ('foo_baz', 'Foo Baz'))
>>> Types.keys()
('foo_bar', 'foo_baz')
>>> Types.values()
('Foo Bar', 'Foo Baz')
>>> 'foo_bar' in Types
True

Extended usage:
===============

.. code-block:: python

>>> class Types2(choose.Choices):
>>> BAR = choose.Choice('foo_bar', 'Foo Bar', default=False)
>>> BAZ = choose.Choice('foo_baz', 'Foo Baz', default=False)
>>> FOO = choose.Choice('foo_foo', 'Foo Foo', default=True)
>>>
>>> @classmethod
>>> def get_default(cls):
>>> return next(
>>> (item for item in cls.keys() if item.opts.default is True),
>>> None,
>>> )
>>>
>>> Types2.BAR.opts.default
False
>>> Types2.BAR.opts.not_existing_attr is None
True
>>> 'foo_bar' == Types2.get_default()
False
>>> Types2.BAR == Types2.get_default()
False
>>> 'foo_foo' == Types2.get_default()
True
>>> Types2.FOO == Types2.get_default()
True

Usage in Django:
================

.. code-block:: python

class AModel(models.Model):
class AChoices(choose.Choices):
X = choose.Choice('x', 'X')
Y = choose.Choice('y', 'Y')

choice = models.CharField(max_length=63, choices=AChoices.items())
Release History

Release History

This version
History Node

2.0.0

History Node

1.0.0

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
choose-2.0.0.tar.gz (2.8 kB) Copy SHA256 Checksum SHA256 Source Jun 30, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting