caktus/django-timepiece — pull request #773 by rebecca-caktus (2014-01-04 03:45:17+00:00)
Title: Constants utility

I got the idea of a Constants utility from another project we work on. I thought it was a pretty cool idea that would allow us to use model constants in a more concise, consistent, and reusable way - while still allowing us to use typical Django conventions like `get_FOO_display()`. It's hardly necessary but I'm interested to see what others think.

```
class Entry(models.Model):
STATUSES = Constants(
unverified=('0', 'Not Verified'),
verified=('1', 'Verified'),
approved=('2', 'Approved'),
invoiced=('3', 'Invoiced'),
uninvoiced=('4', 'Not Invoiced'),
)
status = models.CharField(max_length=1, choices=STATUSES.choices(),
default=STATUSES.unverified)

>>> entry = Entry.objects.create()
>>> entry.status
'0'
>>> entry.get_status_display()
'Not Verified'
>>> entry in Entry.objects.filter(status=Entry.STATUSES.unverified)
True
```