I've searched far and wide, and haven't come up with a solution despite this probably being a simple fix.
Models.py:
class Leaderboard(models.Model):
name = models.CharField(max_length=25)
def __str__(self):
return self.name
class Score(models.Model):
leaderboard = models.ForeignKey(Leaderboard, on_delete=models.CASCADE)
player_name = models.CharField(max_length=25)
score = models.IntegerField()
time_set = models.DateTimeField(null=True, blank=True)
def __str__(self):
return f"{self.player_name} - {self.leaderboard} [{self.score}]"
views.py
def index(response, name):
# ls = Leaderboard.objects.get(name=name)
sorted = Leaderboard.objects.filter(name=name).order_by('-score')
return render(response, "highscores/leaderboard_ranks.html", {"ls": sorted})
And the relevant template part of the code.
{% for item in ls %}
<tr>
<td></td>
<td>{{item.player_name}}</td>
<td>{{item.score}}</td>
<td>{{item.time_set}}</td>
</tr>
{% endfor %}
And this just outputs blank rows in the table. What am I missing?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…