Search code examples
djangouppercase

how to make all letters lowercase in Django model?


I want to make both the integer choices uppercase in my models.py, but even though I write them uppercase (CASE1, CASE2), they don't change in browser? Why?

class Cases(models.IntegerChoices):
        CASE1 = 1,
        CASE2 = 2,

(everything I type, like Case1, caSe1, casE1 and stuff, everything I type results in Case1.


Solution

  • To add a label for each choice, provide a string as the second element in the tuple after the value

    class Cases(models.IntegerChoices):
        CASE1 = 1, 'CASE1'
        CASE2 = 2, 'CASE2'
    

    https://docs.djangoproject.com/en/4.0/ref/models/fields/#enumeration-types