Access to related Objects inside a model propery -


i run problems django models. example code better word:

class cart(models.model):     updated_at = models.datetimefield(auto_now=true)     created_at = models.datetimefield(auto_now_add=true)      def __unicode__(self):         return u'date %s;'%(self.created_at)     def __str__(self):         return self.__unicode__()      def _total_items(self):         """ totale n di oggetti """         = 0         in self.items.all:             += i.quantity         return     total_items = property(_total_items)  class item(models.model):     cart = models.foreignkey(cart)     quantity = models.positiveintegerfield()     def __unicode__(self):         return u'product %s'%(self.id)     def __str__(self):         return self.__unicode__() 

but, when call cart property here's in python console:

>>> a.total_items traceback (most recent call last):   file "<console>", line 1, in <module>   file "models.py", line 49, in _total_items     in self.item_set.all: typeerror: 'relatedmanager' object not callable 

try replacing line

for in self.items.all: 

with one

for in self.items.all(): 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -