#NEWLINE# @ receiver ( post_save , sender = models . ProductTransaction ) #NEWLINE# def update_cached_product_quantity( sender , instance , created , **kwargs ) : #NEWLINE# #INDENT# product_obj = instance . product #NEWLINE# if created : #NEWLINE# #INDENT# product_obj . qty += instance . qty #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# product_obj . qty = product_obj . transactions . quantity ( ) #NEWLINE# #UNINDENT# product_obj . save ( )