On May 23, 10:45 pm, Carsten Jantzen <cars...@jantzens.net> wrote:

> When I load the player I would like to see his latest stats.
> If I goto the players page I would like to be able to view when and
> what skill changed.
>
> I am looking for a good way to implement it.
> I was thinking to make the skill it's own object and make a one to
> many relation on the player.
> What I am afraid of is that the same skill will show up multiple times
> when loading the player.

There are many ways to tackle this problem, and the "best" one depends
on your game's rules. Your above solution would indeed return the
whole history, and you'd need to filter it out to only get the last
value for each skill. A PITA to work with and not exactly efficient...

If it's only for stats and you have no other reason to turn skills
into proper models, the simplest thing would be to add a
"SkillChanged" model, ie (Q&D):

class SkillChange(models.Model):
    player = models.ForeignKey(Player)
    skill = models.CharField()
    value = models.IntegerField()
    date = models.DatetimeField(auto_now_add=True)

then detect skill changes using properties (or explicit getters /
setters) to access your Player's class skills fields and create a new
SkillChange for each skill update.

Or use any of the solutions Andre suggested....

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.

Reply via email to