I am trying to use the StatusModel feature of Carl Meyer's awesome django-model-utils package to create a model that has a status field. It's a very nice design in which you subclass your model from StatusModel
and pass a Choices
object to a field on the model called STATUS, which automatically creates 'status' and 'status_changed' fields on the database representation.
I would like for my status field to have a separate human-readable value than its database representation, and the documentation for the Choices
class says that it can be passed a two-tuple in which the first value is the database representation of the choice and the second is the human-readable value. But when I try doing this with my StatusModel using the above Choices
object, I still get the database representation when I use the status field in a template.
Here's an excerpt of my model class:
from django.utils.translation import ugettext as _
from model_utils import Choices
from model_utils.models import StatusModel
STATUS_CHOICES = Choices(
('awaiting_approval', _('Awaiting approval')),
('returned_to_submitter', _('Returned to submitter')),
('approved', _('Approved')),
('denied', _('Denied')),
)
class Petition(StatusModel):
STATUS = STATUS_CHOICES
...
and here's my template:
<table>
<tr>
<th>Status</th>
</tr>
{% for petition in petitions %}
<tr>
<td>{{ petition.status }}</td>
<!-- expecting "Awaiting approval" but it displays "awaiting_approval" -->
</tr>
{% endfor %}
</table>
How do I get the model class to return the human readable status? Or does StatusModel
not support that feature of the Choices
object?