Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django choices. How to set default option?

Tags:

django

How to set default STATUSES option ?

class Order(models.Model):     STATUSES = (         (u'E', u'Expected'),         (u'S', u'Sent'),         (u'F', u'Finished'),     )      status = models.CharField(max_length=2, null=True, choices=STATUSES) 
like image 974
belisasun Avatar asked Oct 04 '12 10:10

belisasun


1 Answers

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]) 
like image 145
rockingskier Avatar answered Sep 19 '22 09:09

rockingskier