TextChoice parse

I have classes as below.

class ClientStatus(models.TextChoices):
        ACTIVE = "active",  "Active"
        ON_TRIAL = "trial",  "On Trial"

Now, if I know a display name, like “On Trial”, how to get its value (“trial”)?

Where are you needing to retrieve this information?

If you use those choices in a select field, it is the value that is returned to the form, not the display value.

On UI, when search client by status, user will only know the display names, so they will type in like “On Trial” to search the client. Internally I need to convert it to “trial” base on this class to query the client class.

Why would you have them type in the status rather than allowing them to select it from the drop-down? It seems to me to create more chance for errors. (e.g. entering “on trial” or “ontrial” rather than “On Trial”.)

It’s not a create or change screen, but a list. I only provided a search field for all columns, not just for the status. If I make search a drop down for status search, it’s too heavy for the list screen unless such selection can be somehow merged together with the search field as input choices.

Very easily done, and is going to be a lot more reliable and user-friendly than requiring keyboard input. (The specifics for this would be dependent upon how you’re handling the input currently in both the template and the view.)

About my view and template, the Client view is a class extended from Django ListView. it has method get_queryset(self) defined.
Its template is mainly a table listed all the clients from the method above. One of the table column is ‘Status’, which display the client status display name from the class ClientStatus.
On top of the table there is a search field, with which, user can type in some text and hit search button.