So this isn't EXACTLY my code but it is close enough to show what I have. Also the naming is only for this site so if its not really clear forgive me. Its much clearer in the actual code.
class Member(models.Model): team = models.IntegerField(default=0) match = models.ForeignKey(Match, null=True, blank=True) def engage(self, match_instance, team_number): self.match = match_instance self.team = team_number self.save() class NPCGeneric(models.Model): speed = models.IntegerField(default=1) difficulty = models.IntegerField(default=0) class NPCInstance(Member): generic = models.ForiegnKey(NPCGeneric); status = models.CharField(max_length=50) def engage(self, match_instance, team_number): new_instance = NPCInstance(generic=self) new_instance.save() return new_instance.engage(match_instance, team_number) class Player(Member): name = models.CharField(max_length=100) class Match(models.Model): event_members =  def __init__(self, *args, **kwargs): retval = super(Match, self).__init__(*args, **kwargs) if(args and hasattr(args, '__iter__')): teams = args args = args[1:] self.__init_new__(teams) elif(self.id): self.__init_existing__() return retval def __init_new__(self, teams): new_teams =  for team in teams: new_team =  new_teams.append(new_team) team_number = new_teams.index(new_team) for event_member in team: team_member = event_member .engage(self, team_number) team_member .save() new_team.append(team_member) self.event_members = new_teams def __init_existing__(self): new_teams =  def add_list(list, member, team): while(list.__len__() < (team + 1)): list.append() list[team].append(member) for event_member in self.member_set.all(): try: member = event_member.npcinstance except: member = event_member.player add_list(new_teams, member, member.team) self.event_members= new_teams
So this is where I start thinking that there has to be a better cleaner way. Unfortunately my brain just keeps getting stuck on what I already have.
I'd love to know if anyone can suggest a cleaner/Pythonic way for holding the Members in the Match class. specifically:
- The initialising just seems very odd and clumsy. I'm afraid I will introduce errors this way.
- a better way of representing teams other than a list of lists