I have the following models:
class Competition(models.Model): # ... class Result(models.Model): # ... competition = ForeignKey(Competition, on_delete=models.CASCADE, related_name='individual_results', related_query_name='individual_results') athlete = ForeignKey(Athlete, on_delete=models.CASCADE) class Athlete(models.Model): # ... What I'd like to do is create an overview for each athlete and display the results for that athlete grouped by competition.
Tried something like this:
athlete = Athlete.objects.get(pk=1) competitions = Competition.objects .prefetch_related('individual_results') .filter(individual_results__athlete=athlete) But when I do competition.indvidual_results.all in a template, it displays all results from the competition and not only the ones for that athlete.