Django: Custom Save method for Many-to-Many relation

柔情痞子 提交于 2019-12-04 16:59:30

You could make use of django's m2m_changed, pre_save/post_save, pre_delete/post_delete signals on the Model containing the relation, and do the related logic there.

Timmy's answer is definitely correct and works. For your special case however, I am wondering, if you should not handle that logic in the view, where you manage the order and order items and enforce the recalculation there, since the adding, editing and deleting of order items all belong together and belong to the order.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!