On Tue, Nov 23, 2010 at 3:13 PM, Li You <vbs0...@gmail.com> wrote: > Let me describe this problem in more detail: > I have a Game model for each game. This model can be seen as a list of > all games, such as, > > class Game(models.Model): > name = models.CharField(max_length = 128, unique = True) > available = models.BooleanField(default = True) > timestamp = models.DateTimeField(auto_now_add=True) > > And usually a user just plays with a few of games, but there maybe > hundreds of games. > A user may have different level in different games, so I need to keep > record of the user's level in each game. > > At the beginning, I want to create a table for each game. Only users > who play that game get their level logged in the game's table. > > By using many-to-many field, I can record the level info of all games > in a single table. But I am a little afraid of the performance... > > That is the origin of this question. Thank you all. :) >
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.A good programmer will not be lulled into complacency by such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified" - Knuth Your design actually described a through table for M2M, but you don't want to do that because you fear that the performance will be bad. Implement your design, and then work out whether performance will be bad. Even if it is, relational databases are designed to be used in this manner. You could (depending upon the capabilities of your database) partition the through table based upon the game type. With this database configuration, you would have the effect of having one table per game type, but without adding unnecessary complexity to your software. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.