I'm trying to sort a list of Player objects in Django1.10 and Python 3.5. But it is impossible for me and I can not find the error.
The object class is the following
class Jugador(models.Model):
#Otras propiedades
rating = models.IntegerField(null=True)
def __cmp__(self, other):
if self.rating < other.rating:
rst = -1
elif self.rating > other.rating:
rst = 1
else:
rst = 0
return rst
To sort the list, after calculating the rating of each player, I save the property and add it to a list, which I would like it to be sorted by the rating property.
def ratingCalculte(jugadores, user, temporada):
result = []
#Calculando rating
.....
.....
jugador.rating = rating
jugador.save()
result.append(jugador)
sorted(result)
return result
The exception is:
unorderable types: Jugador() < Jugador()
I have tried everything, and I do not know what it can do. And previously in a beta version of the application I ordered in the same way and there was no problem.