average - Django counting related objects in model layer -
it possible working:
class book(models.model): voters = models.manytomanyfield(user, blank=true) vote = models.integerfield() # summary of votes def average_vote(self): return int(vote/self.annotate(count('voters')))
maybe this?
class book(models.model): voters = models.manytomanyfield(user, blank=true) vote = models.integerfield() # summary of votes def average_vote(self): return int(self.vote/self.voters.all().count())
let me know if works. haven't tested it.
Comments
Post a Comment