I have an integer field that provides 3 choices for a blog post:
class Post(models.Model):
STATUS_DRAFT = 0
STATUS_PUBLISHED = 1
STATUS_DELETED = 2
STATUS_CHOICES = (
(STATUS_DRAFT, 'draft'),
(STATUS_PUBLISHED, 'published'),
(STATUS_DELETED, 'deleted'),
)
status = IntegerField(choices=STATUS_CHOICES, default=STATUS_DRAFT)
When I render this in a template with {{ blog.status }}
it prints the integer value (0, 1, 2
). How can I call it to print the string value (draft, published, deleted
)?