Wednesday, April 16, 2014

Re: How to store variable length list of dict-type objects with FKs in Django SQL DB

To clarify, I have a model, let's call it MatchHistory, that stores a fixed set of statistics about a match (ex. points, kills, etc).

Example JSON for the stats:

u'stats': {   u'assists': 2,
              u'championsKilled': 6,
              u'doubleKills': 1,
              u'goldEarned': 7613,
              u'goldSpent': 7330,
              u'killingSprees': 2,
              u'largestKillingSpree': 3,
              u'largestMultiKill': 2,
              u'level': 13,
              u'magicDamageDealtPlayer': 39300,
              u'magicDamageDealtToChampions': 13151,
              u'magicDamageTaken': 7341,
              u'minionsKilled': 95,
              ...
}


These will be singly present for each match.

However, for any given match, in addition to the above data, there is another JSON object that I receive, listing the # of "fellowPlayers" (teammates and/or opponents) which can vary from 0-11 inclusive. For every fellowPlayer, their championId and summonerId would be linked to the model. These are the character they controlled in that game, and the actual player controlling said character. teamId can only have 1 of 2 values (constants).

On Wednesday, April 16, 2014 7:34:30 PM UTC-4, Kreychek wrote:

Let's say I'm getting some JSON in the format of...

"fellowPlayers": [              {                 "championId": 110,                 "teamId": 100,                 "summonerId": 34258805              },              {                 "championId": 9,                 "teamId": 100,                 "summonerId": 19923759              },
{ "championId": 46, "teamId": 200, "summonerId": 2112359 },
... ]

...that can have a variable # of entries (from 0-11, inclusive), but each entry has those 3 attributes, 2 of which should map to other tables (championId and summonerId).

How would I want to define a table/model in Django to store the list of fellowPlayers (of unknown length)?

If any more information is needed please comment.

If this can't be directly done, how would you suggest handling such a situation? My initial thought was to hardcore in a # of fields (fellow_player_1, fellow_player_2, etc) based on what I expect the maximum # of entries to be, but that approach seems like it could be improved on a lot, although 11 isn't too bad in terms of hardcoding.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/965e674e-f289-447a-92cf-763d5a9d8f5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment