Reputation: 47
The model looks as follows. Where apps
is a field which can have only app1
and app2
as choices which can be incremented in the future. Also, each app choice (app1
, app2
) should be a model with fields representing features. How to implement this in Django models.
apps:
app1:
feature_app1_1: "Data"
feature_app1_2: "Data"
app2:
feature_app2_1: "Data"
feature_app2_2: "Data"
Upvotes: 0
Views: 57
Reputation: 133
This sounds like you need many-to-many relationships. The Many to Many field will limit choices to the models you have created, so if you only have 2 apps, then those will be your only choices. As you add more, they will appear.
So, I imagine you want something like this:
You say "apps" is a field, so if that is a field on a parent model.
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.
Your parent class will have a many to many field ("apps") linking to all the apps you want on it, and then each app will link to every feature ("features") you need. Then each feature contains the data.
Upvotes: 1