Best practice for Python & Django constants

Posted by Dylan Klomparens on Stack Overflow See other posts from Stack Overflow or by Dylan Klomparens
Published on 2012-10-10T15:20:08Z Indexed on 2012/10/10 15:37 UTC
Read the original article Hit count: 847

Filed under:
|

I have a Django model that relies on a tuple. I'm wondering what the best practice is for refering to constants within that tuple for my Django program. Here, for example, I'd like to specify "default=0" as something that is more readable and does not require commenting. Any suggestions?

Status = (
    (-1, 'Cancelled'),
    (0, 'Requires attention'),
    (1, 'Work in progress'),
    (2, 'Complete'),
)

class Task(models.Model):
    status = models.IntegerField(choices=Status, default=0) # Status is 'Requires attention' (0) by default.

EDIT:

If possible I'd like to avoid using a number altogether. Somehow using the string 'Requires attention' instead would be more readable.

© Stack Overflow or respective owner

Related posts about python

Related posts about django