I have many choice fields and each option corresponding to a number. This number will be used for later calculations.
Here is an example. I defined a dictionary which defines the value to each input:
driven_factors = {
"Education":{
"A": 1.29,
"B": 0.98,
"C": 0.72,
},
}
and the model is like:
Education_choices= list(driven_factors.get("Education").keys())
Education= models.CharField(max_length=50, choices=Education_choices)
Unfortunately, it does not work, because Education_choices
is like ['A', 'B', 'C']
other than a sequence of pairs like [('A', 'x'), ('B', 'y',...)]
How should I fix this? Or are there other approaches to do this?
Edit:
If transfer Education
to list: it will be like
Education = (
('A', 1.29),
('B', 0.98),
('C', 0.72),
)
However, as designed for choices, it is the list of pairs like ('value in database', 'human-readable name'). Is it appropriate to use numberical value as the 'human-readable name', in the sense of design?