I am trying to update a Promotion field through a signal sent when a Review field is updated. Review has a many-to-one relationship with Promotion.
I must be making some rookie mistake, but I can't work out why its not working. The code fails to return anything for the line p_qs= Promotion.objects.filter(id=promotion_id) and therefore the index on the next line is out of bounds. def update_review_average(sender,instance,signal,*args,**kwargs): """ updates the average for the review on promotions any time that a review is updated, or created. """ promotion_id = instance.promotion qs = Review.objects.filter(promotion = promotion_id) x=0 y=0 for r in qs: x=x+r.promo_rating y=y+1 average = y and x/y or 0 # save average to the relevant Promotion p_qs = Promotion.objects.filter(id=promotion_id,) p=p_qs[0] p.av_rating = average p.save() MerMer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---