Django choices. How to set default option?

It's an old question, just wanted to add the now availabel Djanto 3.x+ syntax:

class StatusChoice(models.TextChoices):
    EXPECTED = u'E', 'Expected'
    SENT = u'S', 'Sent'
    FINISHED = u'F', 'Finished'

Then, you can use this syntax to set the default:

status = models.CharField(
    max_length=2,
    null=True,
    choices=StatusChoice.choices,
    default=StatusChoice.EXPECTED
)

status = models.CharField(max_length=2, null=True, choices=STATUSES, default='E')

or to avoid setting an invalid default if STATUSES changes:

status = models.CharField(max_length=2, null=True, choices=STATUSES, default=STATUSES[0][0])

Tags:

Django