This is my attempt at a convenience class for Django model choices which will use a [Small]IntegerField for storage. It's very similar to [jacobian's version](http://www.djangosnippets.org/snippets/1664/), but I wanted to be able to use simple attributes for access to the integer values.
It's not technically dependent on Django, but it's probably not a datatype that would be useful for much else. Feel free to do so however if you have a use-case.
>>> statuses = Choices(
... ('live', 'Live'),
... ('draft', 'Draft'),
... ('hidden', 'Not Live'),
... )
>>> statuses.live
0
>>> statuses.hidden
2
>>> statuses.get_choices()
((0, 'Live'), (1, 'Draft'), (2, 'Not Live'))
This is then useful for use in a model field with the choices attribute.
>>> from django.db import models
>>> class Entry(models.Model):
... STATUSES = Choices(
... ('live', 'Live'),
... ('draft', 'Draft'),
... ('hidden', 'Not Live'),
... )
... status = models.SmallIntegerField(choices=STATUSES.get_choices(),
... default=STATUSES.live)
It's also useful later when you need to filter by your choices.
>>> live_entries = Entry.objects.filter(status=Entries.STATUSES.live)