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

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -