Skip to content

orlnub123/choices.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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+

About

A wrapper around Django's choices.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages