78
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])
15
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
)
- [Django]-Set language within a django view
- [Django]-Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)
- [Django]-How to resolve AssertionError: .accepted_renderer not set on Response in django and ajax
Source:stackexchange.com