Metadata-Version: 2.1
Name: constants_set
Version: 0.3
Summary: Simple constants sets for Python
Home-page: https://github.com/raphael-leger/constants-set
Author: Raphaël Léger
Author-email: raphael+pypi@nodixo.com
License: MIT
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
        ```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
        ```python
        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
        ```python
        from constants_set import ConstantsSet
        from rest_framework import serializers
        
        
        class BookSerializer(serializers.Serializer):
            type = serializers.ChoiceField(required=True, choices=Book.TYPES.to_choices())
        ```
        
Platform: UNKNOWN
Description-Content-Type: text/markdown
