Given below is my Model definition and I have added this module part of the Admin. I’m trying to create new row and while selecting value ‘3’ or any other value for Duration field(listed as select fields), I get the following error.- “Value 3 is not a valid choice”.
Please provide your inputs.
Model Definition
NO_OF_HRS = (
(‘1′,’One’),
(‘2′,’Two’),
(‘3′,’Three’),
(‘4′,’Four’),
(‘5′,’Five’),
(‘6′,’Six’),
(‘7′,’Seven’),
(‘8′,’Eight’),
(‘9′,’Nine’),
(’10’,’Ten’),
(’11’,’Eleven’),
(’12’,’Twelve’),
)
YR_MONTH = (
("Y", "Year"),
("M", "Month"),
)
POS_STATUS = (
("A", "Active"),
("C", "Closed"),
)
datecreated = models.DateTimeField()
volposition = models.CharField(max_length=300)
roledesc = models.CharField(max_length=5000)
noofhours = models.IntegerField(blank = True,null = True)
Qualreqt = models.CharField(max_length=8000)
Duration = models.IntegerField(choices=NO_OF_HRS,blank = True,null = True)
Durationyrmon = models.CharField(choices=YR_MONTH,max_length=10)
posstatus = models.CharField(choices=POS_STATUS,max_length=1)
teamrelation = models.CharField(max_length=50)
When you use
choices, the first value of the tuple is the value that will be stored in the database and the second value is the value that will be shown in the admin.In
NO_OF_HRSthe values are strings (for example ‘1’, ‘2’) but it is amodels.IntegerFieldso the values should be integers. That’s why you’re now getting an error.