I have this model:
class ScoringModel(model.Model):
red_score = models.SmallIntegerField()
blue_score = models.SmallIntegerField()
I'm trying to sort a query set based on whichever is greater between the two. Now, taking the sum of them wouldn't work because that means a score of 90 to 0 would have a lower rank than a score of 50 to 50, which is not what I want. (I'm trying to find a list of high scores, basically.)
I tried adding a function inside of the model, as such:
class ScoringModel(model.Model):
red_score = models.SmallIntegerField()
blue_score = models.SmallIntegerField()
def max_score(self):
return self.red_score if self.red_score > self.blue_score else self.blue_score
Which doesn't work, since the order_by
function doesn't support function return values (ie ScoringModel.objects.order_by('-max_score')
and ScoringModel.objects.order_by('-max_score()')
fail to run).
Any help would be very appreciated