constants-set-0.5
توضیحات
Simple constants sets for Python
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | constants-set-0.5 |
| نام | constants-set |
| نسخه کتابخانه | 0.5 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Raphaël Léger |
| ایمیل نویسنده | raphael+pypi@nodixo.com |
| آدرس صفحه اصلی | https://github.com/raphael-leger/constants-set |
| آدرس اینترنتی | https://pypi.org/project/constants-set/ |
| مجوز | MIT |
# 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
```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 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
```python
from rest_framework import serializers
class BookSerializer(serializers.Serializer):
type = serializers.ChoiceField(required=True, choices=Book.TYPES.to_choices())
```
نحوه نصب
نصب پکیج whl constants-set-0.5:
pip install constants-set-0.5.whl
نصب پکیج tar.gz constants-set-0.5:
pip install constants-set-0.5.tar.gz