class Player(models.Model):
name = models.CharField(max_length=30)
class Toon(models.Model):
name = models.CharField(max_length=30)
player = models.ForeignKey(Player, on_delete=models.CASCADE)
I’m trying to create a detail view for players which lists the toons associated with the player. Like this:
class PlayerDetailView(DetailView):
model = Player
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['toons'] = Toon.objects.filter(player.id=???)
return context
How do I reference the pk field passed to the view, or am I thinking about this in the wrong way?
Thanks in advance