[Answer]-How to store variable length list of dict-type objects with FKs in Django SQL DB

1👍

That is a Many-to-one relation.

class FellowPlayer(models.Model):
    champion = models.ForeignKey('Champion')
    team_id = models.IntegerField(unique=True)
    summoner = models.ForeignKey('Summoner')

    match_history = models.ForeignKey('MatchHistory')

class Summoner(models.Model):
    match_history = models.ForeignKey('MatchHistory')


class Champion(models.Model):
    match_history = models.ForeignKey('MatchHistory')


class MatchHistory(models.Model):
    pass

And you will make the queries backwords. Ex:

# select all the fellow players objects who belong to other model with pk=1
FellowPlayer.objects.filter(match_history__pk=1)

You can find more examples in that link.

Leave a comment