Login

Tag "enum"

Snippet List

More readable Enumeration class for Django choices

We currently use two-level tuples to specify choices of a field in models or forms. But, because it has only (value, verbose name) pair, the readability is bad whenever we indicate a specific choice value in our Python codes. So I made a small class that does "magic" for this: A Named Enumeration. Instead of `myobj.status == 0`, use `myobj.status == STATUS.UNREVIEWED`, for example.

  • choices
  • model
  • orm
  • enumeration
  • enum
Read More

1 snippet posted so far.