Simple Enums for Django when working with choices in model fields.
Project description
# Django Enumerify #
## Installation ##
```
pip install django-enumerify
```
## Usage ##
```
#!python
# .../app/enums.py
from django.utils.translation import gettext as _
from enumerify.enum import Enum
class GroupKind(Enum):
PUBLIC = 0
PRIVATE = 1
i18n = (
_('Public'),
_('Private'),
)
# .../app/models.py
from django.db import models
from enumerify import fields
from .enums import GroupKind
class Group(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField()
description = models.TextField()
kind = fields.SelectIntegerField(blueprint=GroupKind, default=GroupKind.PUBLIC)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
def __unicode__(self):
return u"Group: %s" % self.title
```
## Tests ##
```
#!python
$ python testapp/tests/runtests.py
```
## Installation ##
```
pip install django-enumerify
```
## Usage ##
```
#!python
# .../app/enums.py
from django.utils.translation import gettext as _
from enumerify.enum import Enum
class GroupKind(Enum):
PUBLIC = 0
PRIVATE = 1
i18n = (
_('Public'),
_('Private'),
)
# .../app/models.py
from django.db import models
from enumerify import fields
from .enums import GroupKind
class Group(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField()
description = models.TextField()
kind = fields.SelectIntegerField(blueprint=GroupKind, default=GroupKind.PUBLIC)
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
def __unicode__(self):
return u"Group: %s" % self.title
```
## Tests ##
```
#!python
$ python testapp/tests/runtests.py
```
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
File details
Details for the file django-enumerify-0.5.2.tar.gz
.
File metadata
- Download URL: django-enumerify-0.5.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d55b5b37fd1018895445a5773a7c4751c4a6d50ced8857cffa72c4149c3e02f9 |
|
MD5 | af6bf34fb209bc1f1777bbaec99749d2 |
|
BLAKE2b-256 | 5595cd289e07188d7d8ca538fcf5e4ad7cb2548ccc60bdb690da9659006d0753 |