I have a field in my module that is used to hold the status of the object.
So far I have used:
ORDER_STATUS = ((0, 'Started'), (1, 'Done'), (2, 'Error'))
status = models.SmallIntegerField(choices=ORDER_STATUS)
Its easy to convert one way:
def status_str(self): return ORDER_STATUS[self.status][1]
The problem is when updating. I find myself having code like this:
order.status = 2 # Error Status
Which is quite awful and gets really hard to synchronize. I guess a solution would be something similar to C's enum{}. Or perhaps there is a whole different way to tackle this problem ?
Thanks
question from:
https://stackoverflow.com/questions/2142055/django-best-way-to-implement-status-field-in-modules 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…