I have a website which catalogs various climbs. These climbs have difficulty grades associated with them, which are non-integer values. Users can also submit reviews of the selected climbs, and assign their own suggested difficulty grade. I want to be able to assign integer values to these difficulties, average them, and then output the result back in terms of the grading system.
For example, if the rating system goes 5.1, 5.2, 5.3 ... 5.9, 5.10, 5.10a, 5.10b etc.. how do I assign an integer value to each of these fields so that I can average them later?
class Climb(models.Model):
GRADES = (
('5.15', '5.15'),
('5.14', '5.14'),
... (more difficulties here)
('5.1', '5.1'),
)
name = models.CharField(max_length=255, unique=True)
grade = models.CharField(max_length=255, choices=GRADES)
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return "%s %s" % (self.name, self.grade)
I tried the following:
class Climb(models.Model):
GRADES = (
('20', '5.15a'),
('19', '5.14d'),
('18', '5.14c'),
...
('1', '5.1'),
)
But ran into issues later because I have another form where uses can select the climb, and the climb should display ideally as "Climb_name climb_grade" where climb_grade is "5.15a" or "5.9" or whatever, but instead was showing up as "20" or "10" or whatever integer I had attached to that difficulty.
Any ideas?