How can I store history of ManyToManyField using django-simple-history.

自古美人都是妖i 提交于 2019-12-20 04:48:40

问题


How can I store history of ManyToManyField using django-simple-history. I used HistoricalRecords with attribute m2m_filds but it is throwing error: unexpected keyword argument 'm2m_fields'


回答1:


I'm macro1 on GitHub, and I guess de facto maintainer of django-simple-history.

From your question it seems that you're just asking about general ManyToManyField support compared with other fields. The short answer is that we do not currently support it.

ManyToManyFields actually create an in-between model that represents the relationship between the two models you're working with.

If you want tracking on that relationship I would suggest making a 'through' model representing the relationship and passing that into the ManyToManyField constructor. You could then register that through model to have its history tracked. If you get errors like "unexpected keyword argument 'm2m_fields'" with that set up please open an issue in our tracker.




回答2:


As the author of django-simple-history says this isn't possible to detect change in only specific fields because

As you already know simple-history doesn't look at the values being saved at all. It blindly saves a new historical version on every save or delete signal.

He also says it may be possible Field Tracker do this job.



来源:https://stackoverflow.com/questions/35312334/how-can-i-store-history-of-manytomanyfield-using-django-simple-history

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