This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A helpful decorator for choice fields (Django choices or SQLAlchemy ChoiceType). Do choices the pythonic way.

Why create ORM Choices?

I got sick and tired of using choice fields in Django ORM and SQLAlchemy. Look here for a context

For example:

# Conference Application Choice Fields
CONFERENCE_STATUS_ACCEPTING_CFP = "Accepting Proposals"
CONFERENCE_STATUS_CLOSED_CFP = "Proposal submission closed"
CONFERENCE_STATUS_ACCEPTING_VOTES = "Accepting Votes"
CONFERENCE_STATUS_SCHEDULE_PUBLISHED = "Schedule Published"

CONFERENCE_STATUS_LIST = ((1, CONFERENCE_STATUS_ACCEPTING_CFP),
                          (2, CONFERENCE_STATUS_CLOSED_CFP),
                          (3, CONFERENCE_STATUS_ACCEPTING_VOTES),
                          (4, CONFERENCE_STATUS_SCHEDULE_PUBLISHED),
                          )

# Using it in a model:

class Conference(Model):
    status = models.PositiveSmallIntegerField(
        default=1, choices=CONFERENCE_STATUS_LIST)

I have no Idea what 1 is (I mean its not really obvious that it means CONFERENCE_STATUS_ACCEPTING_CFP when CONFERENCE_STATUS_LIST is declared in some other file).

I needed a clean and DRY way of making use of Choice Fields.

Introducing choices:

from orm_choices import choices

@choices
class ConferenceStatus:
    class Meta:
        ACCEPTING_CFP = [1, "Accepting Proposals"]
        CLOSED_CFP = [2, "Proposal submission closed"]
        ACCEPTING_VOTES = [3, "Accepting Votes"]
        SCHEDULE_PUBLISHED = [4, "Schedule Published"]

# Using it in a model:

class Conference(Model):
    status = models.PositiveSmallIntegerField(
        default=ConferenceStatus.ACCEPTING_CFP,
        choices=ConferenceStatus.CHOICES)

What did just happen? Crazy (not really). I know, right! Declare all your variables in Meta class (within ConferenceStatus). And apply the orm_choices decorator to ConferenceStatus class. And boom! Your ConferenceStatus now has these attributes:

ConferenceStatus.ACCEPTING_CFP  # This will return `1`
ConferenceStatus.ACCEPTING_VOTES  # This will return `2`

# And so on...

And it will add a new CHOICES attribute too.

print(ConferenceStatus.CHOICES)
# Will Print
((1, "Accepting Proposals"), (2, "Proposal submission closed"), (3, "Accepting Votes"), (4, "Schedule Published"))

Clean and DRY!

Release History

Release History

0.2.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
orm_choices-0.2.0-py2.py3-none-any.whl (4.8 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Nov 26, 2015
orm-choices-0.2.0.tar.gz (2.9 kB) Copy SHA256 Checksum SHA256 Source Nov 26, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development 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