Skip to main content

Handle choices field easily

Project description

https://circleci.com/gh/olist/easy-choices.svg?style=shield

It’s a library deeply inspired by Choices from django-model-utils. However, sometimes we just need to use Choices rather than all the features provided by django-model-utils.

Requirements

  • Python >= 3.5

Usage

The easy-choices package is hosted on our PyPI repository.

You can install the latest version of easy-choices using pip:

$ pip install easy-choices

And use easy-choices as it’s demonstrated below:

from django.db import models
from easy_choices import Choices

status_choices = Choices(
    ("sent", "Sent"),
    ("delivered", "Delivered"),
)

class Product(models.Model)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    status = models.CharField(max_length=10, choices=status_choices.to_django_choices())

    @property
    def is_delivered(self):
        # You can use status_choices as a Enum
        return self.status == status_choices.delivered

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 easy-choices, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size easy_choices-1.0.0-py3-none-any.whl (7.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size easy-choices-1.0.0.tar.gz (7.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page