What does work get_FOO_display() method in django?

Md Sadiqul Islam
1 min readMar 1, 2023

--

In Django, the get_FOO_display() method is automatically created for every field that has choices set in a model. Here, FOO represents the name of the field. The purpose of this method is to return a human-readable version of the value stored in the field, as defined in the choices option.

For example, let’s say you have a model with a gender field that has choices set to MALE and FEMALE. When you create an instance of this model with gender set to MALE, the get_gender_display() method will return the string "Male". Similarly, if you set gender to FEMALE, the method will return the string "Female".

You can use the get_FOO_display() method in your code to display the human-readable value of a field in your templates or views. For example, you might use this method to display the gender of a user in a template.

In summary, the get_FOO_display() method is a built-in method in Django models that returns the human-readable version of a field value, as defined in the choices option.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response