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

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -