When defining Django model choices with integers, you might be tempted to use sequential numbers:...When defining Django model choices with integers, you might be tempted to use sequential numbers:...
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
When defining Django model choices with integers, you might be tempted to use sequential numbers: 1, 2, 3, 4. Don't.
class OrderStatus(models.IntegerChoices):
PENDING = 1
CONFIRMED = 2
SHIPPED = 3
DELIVERED = 4
This looks clean and streamlined, until your PM says: "We need a PROCESSING status between CONFIRMED and SHIPPED."
class OrderStatus(models.IntegerChoices):
PENDING = 10
CONFIRMED = 20
SHIPPED = 30
DELIVERED = 40
Now both you and your PM will be fine when PROCESSING arrives six months later. Of course, if your PM returns with dozens of new statuses between SHIPPED and DELIVERED, you'll still have a problem. But not with your code.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started