该模型如下所示。其中,apps是一个字段,它只能将app1和app2作为选项,并且可以在将来递增。此外,每个应用程序选择(app1、app2)都应该是一个具有表示功能的字段的模型。如何在Django模型中实现此功能。
apps:
app1:
feature_app1_1: "Data"
feature_app1_2: "Data"
app2:
feature_app2_1: "Data"
feature_app2_2: "Data"发布于 2020-02-20 05:29:52
这听起来像是您需要many-to-many关系。多对多字段将限制您创建的模型的选择,因此如果您只有两个应用程序,那么这些将是您唯一的选择。当您添加更多内容时,它们将出现。
所以,我想你想要这样的东西:
您说"apps“是一个字段,所以如果它是父模型上的一个字段。
Class Foo(models.Model):
apps = models.ManyToManyField(App)
Class App(models.Model):
name = models.Charfield(max_legnth=100) #App name
features = models.ManytoManyField(Feature)
Class Feature(models.Model):
name = models.Charfield(max_legnth=100) #Feature name
...... # Your data fields here. 您的父类将有一个多对多字段(" apps ")链接到您想要的所有应用程序,然后每个应用程序将链接到您需要的每个功能(“feature”)。然后每个特征都包含数据。
https://stackoverflow.com/questions/60307441
复制相似问题