python - Django maximum recursion depth exceeded decimal -


i'm struggling try , figure out why post_save function returning:

exception type:     runtimeerror exception value:    maximum recursion depth exceeded 

here code:

#post save functions of order def orderps(sender, instance=false, **kwargs):     if instance.reference none:         instance.reference = str(friendly_id.encode(instance.id))      #now update amounts order items     total = 0     tax = 0     #oi = orderitem.objects.filter(order=instance)     #for in oi.all():     #    total += i.total     #    tax += i.total_tax      instance.total = total     instance.tax = tax     instance.save()   #connect signal post_save.connect(orderps, sender=order) 

i've commented out order items code now.

instance.total , instance.tax model decimal fields.

it seems post_save function in endless loop, not sure why i've used same format of post_save functions.

any ideas?

you calling instance.save() in post save signal triggering recursively.

all edited fields in signal receiver quite derived other values stored in database creating redundancies. not idea. write properties or cached properties instead:

from django.db.models import sum django.utils.functional import cached_property  class order(model.model):     ...     @cached_property       # or @property     def total(self):          return self.orderitem_set.aggregate(total_sum=sum('total'))['total_sum']      # same tax 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -