本文介绍了Django:“Soft” ForeignField没有数据库完整性检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django项目,有多个django应用程序。其中一个有模型来表示来自外部源的数据(我不控制这个数据)。

I have a Django project that has multiple django "apps". One of them has models to represent data coming from an external source (I do not control this data).

我想让其他应用程序能够引用这个外部应用程序,但我想避免所有的数据库完整性检查的毛刺。我不希望数据库对这些外键有任何约束。

I want my other apps to be able to have references to this "external app" but I want to avoid all the fuzz of the database integrity checks. I don't want the db to have any constraints on these "soft foreign keys".

你知道我如何编写一个自定义字段来模拟一个真正的Django ForeignKey没有在数据库上创建硬约束?

Do you know how I can code a custom field that will emulate a real Django ForeignKey without creating a hard constraint on the database?

也许这已经存在,但我没有在谷歌运气。

Maybe this already exists, but I didn't have any luck on Google.

感谢您的帮助: - )

Thanks in advance for the help :-)

注意:我知道系统与content_types。但我不想要泛型关系。

NB: I'm aware of the generic relations system with the content_types. But I don't want generic relations. I want specific relations to identified models only without hard integrity constraints.

编辑:

我发现相关链接:



  • See here for the complete monkey-patch : http://eve-corp-management.org/projects/ecm/repository/entry/ecm/lib/softfk.py

    这篇关于Django:“Soft” ForeignField没有数据库完整性检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:03