Skip to main content

Simple constants sets for Python

Project description

Constants-set

  • Simple constants sets for Python.
  • Kind of like enums, reusable constants.
  • Kind of convenient for Django and DRF.

Install

pip install constants-set

Use cases

Simple python

from constants_set import ConstantsSet


class Book:
    TYPES = ConstantsSet(["ROMANCE", "ACTION"])

    def __init__(self, type):
        self.type = type

    def get_global_feeling(self):
        if self.type == Book.TYPES.ROMANCE:
            return 'love'
        if self.type == Book.TYPES.ACTION:
            return 'intensity'

Django model

from django.db import models


class BookModel(models.Model):
    type = models.CharField(max_length=30, choices=Book.TYPES.to_choices(), default=Book.TYPES.ROMANCE)

Django rest framework serializer

from rest_framework import serializers

class BookSerializer(serializers.Serializer):
    type = serializers.ChoiceField(required=True, choices=Book.TYPES.to_choices())

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

constants_set-0.5-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

Details for the file constants_set-0.5-py3-none-any.whl.

File metadata

  • Download URL: constants_set-0.5-py3-none-any.whl
  • Upload date:
  • Size: 2.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4

File hashes

Hashes for constants_set-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 577288ce78b66cfbb6204eaa2b45ffeeedfa4dc2e7cc3061b98c0bbbcb0466f3
MD5 bd01b363e91459e0fda8b72e8549492a
BLAKE2b-256 16b33ec1c95cee4bf8c4bfc6fec3749e5448ffd7d5c4dc46e21b2e7204d28703

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page