Relational Fields - Django
I am making a product app to add machines to a product list. Every product had a list of features, like motor type, motor output. Not all have the same features. Each feature has a value, like 2W, 1.5m etc, but this will only be put in once you add a product.
So I wanna add all the possible features to my feature model. Then when I add a machine, I want to choose from the list of features, then fill in the values for that machines features.
So I want to be able to add any feature to any machine, and fill in that features value. So each machine has its own set of features, with unique values.
I'm not sure how to create models for this, as each machine has features with unique values. Some machines have the same features, no开发者_Python百科t the same values.
EDIT: I know I can just add the features inline style, but I want to add a feature once to the DB, and then choose it and fill in the value.
I got this working. Basically I made the features name a foreign key to the features model. so you add features to the features model. then when you add a new product, you simply choose the feature and fill in the rest. the feature fk will be the name field in the product model
精彩评论