I'm trying to generate a list of the best result of each athlete, ordered on time.
Currently I'm just throwing out every duplicate result after getting all results and ordering on time.
I have the following two models:
class Athlete(models.Model):
name = models.CharField(max_length=100)
class Result(models.Model):
athlete = ForeignKey(Athlete, on_delete=models.CASCADE)
time = models.DurationField()
Say the Result table looks like this:
athlete time
------- ----
1 15.00
1 14.00
2 16.00
2 18.00
2 13.00
3 12.00
How do I get the fastest time for each athlete and then sort the list on time? Like this:
athlete time
------- ----
3 12.00
2 13.00
1 14.00