Hi there, I want to collect some statistics about a card game.
So i have three models in my app: Player = holds the player data Hand = the data for one round Partie = The data for a complete game class Player(models.Model): name = models.CharField(max_length=200, unique=True) color = models.CharField(max_length=200, unique=True) def __unicode__(self): return '%s' % self.name class Meta: ordering = ['-name',] class Hand(models.Model): player = models.ForeignKey(Player) date_created = models.DateTimeField('Date',default=datetime.datetime.now) date_changed = models.DateTimeField('Date',default=datetime.datetime.now) round = models.IntegerField("Runde", blank=True, null=True) points_round = models.IntegerField("Points this round", blank=True, null=True) phase = models.IntegerField("Phase",blank=True,null=True) points_partie = models.IntegerField("All Points",blank=True, null=True) def __unicode__(self): return "%s - %s - %s" % (self.player, self.rount, self.date_created) class Meta: ordering = ['player', '-round'] class Partie(models.Model): player = models.ManyToManyField(Player) hand = models.ManyToManyField(Hand) date_created = models.DateTimeField('Datum',default=datetime.datetime.now) def __unicode__(self): return '%s' % self.date_created class Meta: ordering = ['date_created'] def get_phase(self): phase = Partie.objects.filter(spieler=self.spieler).count() return phase In "get_phase" in the Partie model i want to use "round" and points_round" to calculate in which phase the player is. In short: I want to be able to do: phase_raw = Partie.objects.filter(player=self.player, partie=self.id, round=self.round, points_round__lte=9).count() I know that this does not work, it would work for the two mentioned fields if i put the function into the Hand-Model, but then i miss the "partie.id" field. Any hints are welcome... Best regards, michael -- 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+unsubscr...@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/20131108190700.GB15281%40homer.mm. For more options, visit https://groups.google.com/groups/opt_out.