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)
def status_str(self): return ORDER_STATUS[self.status]
order.status = 2 # Error Status
Maybe this question helps you: Set Django IntegerField by choices=… name.
I quote from the accepted answer (with adjustments ;)):
Put this into your class (
STATUS_CHOICES will be the list that is handed to the
choices option of the field):
PENDING = 0 DONE = 1 STATUS_CHOICES = ( (PENDING, 'Pending'), (DONE, 'Done'), )
Then you can do
order.status = Order.DONE.
Note that you don't have to implement an own method to retrieve the (readable) value, Django provides the method