Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

django integerchoices vs textchoices

Relieved Reindeer answered on February 2, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • django integer field example
  • IntegerChoices django

  • django integerchoices vs textchoices

    0

    The choices are on the following format:

    The db_format is what's saved to the DB.

    The display_format is what's displayed when you call get__display

    You basically choose which to save in the DB, the integer or the text choice. The problem is when your model is serialized, if you have field year with choices of YearInSchool(models.IntegerChoices):, you'll have this:

    "year": 1

    in your JSON, but you expect it to show "Freshman", Of course you can manipulate this on the serializer level to show freshman if the year is 1.

    IntegerChoices are much faster when they are looked up, but the are too ambiguous. If I were you, I'd use IntegerChoices every single time and manipulate the response through the serializer to show the text instead of the integer itself.

    Popularity 1/10 Helpfulness 1/10 Language python
    Tags: django python
    Link to this answer
    Share Copy Link
    Contributed on Feb 02 2023
    Relieved Reindeer
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    0

    Django textChoices are of the following format:

    Popularity 1/10 Helpfulness 1/10 Language python
    Tags: django python
    Link to this answer
    Share Copy Link
    Contributed on Feb 02 2023
    Relieved Reindeer
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.