The Design and Development of Choices in Django 3.0
summary
Django 3.0 adds a class-based choices API that packs constant names, values and labels together using enum base types so values compare to plain ints/strs; implementation uses a custom metaclass __new__ to strip labels from classdict, store them, and expose them via a valueβlabel map and a per-member property. The design solves translatable labels, the empty choice via special name trick, and settles on str() returning the underlying value; the feature lands, a beta bug is fixed, and it ships.
AI-written summary Β· about
chapters (11)
- 0:00Introduction to Choices feature
- 1:14Traditional choices in Django
- 2:18History of Django choices feature
- 4:50Proof of concept with enums
- 6:14Development and PR process
- 8:00Design issues encountered
- 13:45Empty choice and dunder str debates
- 14:27Implementation deep dive
- 20:35Meta class and dunder new
- 21:36Property decorator magic
- 23:46Future of choices in Django
