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.
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 Book.TYPES.ROMANCE:
return 'love'
if Book.TYPES.ACTION:
return 'intensity'
Django model
from constants_set import ConstantsSet
from django.db import models
class Book(models.Model):
TYPES = ConstantsSet(["ROMANCE", "ACTION"])
type = models.CharField(max_length=30, choices=TYPES.to_choices(), default=TYPES.ROMANCE)
Django rest framework serializer
from constants_set import ConstantsSet
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 Distribution
constants_set-0.2.tar.gz
(1.6 kB
view hashes)
Built Distribution
Close
Hashes for constants_set-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d473a6a41307d23da3116638032f54efdff94d2f954a5db756d9bb32000250b3 |
|
MD5 | 0082317f8259bda972ac42fcf603c1ee |
|
BLAKE2b-256 | 1779a1330ee3847bf371e6f073a362ff732a5a4d2e370fbf0ecd3bf971c11467 |