Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

A wrapper around Django's choices.

Project description

choices.py

choices.py is a wrapper around Django's choices to make them easier to use.

Example

from django.db import models

from choices import Choices


class Student(models.Model):

    class Year(Choices):

        FRESHMAN = 'FR'
        SOPHOMORE = 'SO'
        JUNIOR = 'JR'
        SENIOR = 'SR'

        @property
        def is_upperclass(self):
            return self in (self.JUNIOR, self.SENIOR)

    year_in_school = models.CharField(
        max_length=2, choices=Year.choices(), default=Year.FRESHMAN.value)

    def is_upperclass(self):
        return self.Year(self.year_in_school).is_upperclass

Installing

Install it from PyPI with pip:

pip install choices.py

Requirements:

  • Python 3.4+

Project details


Download files

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

Files for choices.py, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size choices.py-0.1.1-py2.py3-none-any.whl (4.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size choices.py-0.1.1.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page