且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在运行时在Django中添加动态字段

更新时间:2023-12-06 15:39:40

Django不是用于动态模型的,因为关系数据库不是.在运行时更改模型会产生很多问题.

Django is not made for dynamic models, as relational databases are not. A model change at runtime will create a ton of problems.

您必须通过...来模拟它

You have to simulate it, by...

  • 巧妙使用相关模型
  • 在大字段中存储值,例如JSON作为文本
  • 具有将数据存储为键,值的通用模型;例如带有PK,FK,键,值作为列的表.

您应该尝试第一种方法,只有在无法解决问题时,才尝试其他两种方法.

You should try the first option and only if that does not work out try the other two.