I want to know how to deal with this task. here are the details: this is product_feature model
class Feature(models.Model):
has_value_choice = [
('y', 'Yes'),
('n', 'No'),
]
feature_id = models.AutoField(primary_key=True)
feature_name = models.CharField(max_length=255, null = False)
product_type = models.ForeignKey(Product_type, on_delete=models.SET_NULL, null=True)
feature_has_value = models.CharField(choices=has_value_choice, max_length = 1, null = False)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
class Product_feature(models.Model):
product_feature_id = models.AutoField(primary_key=True)
feature = models.ForeignKey(Feature, on_delete=models.SET_NULL, null=True)
product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True)
product_feature_value = models.CharField(max_length=255, null = False)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
here, I'm passing features data to the template to save features of the specific product in the product_feature model.
<form>
<table class="table table-bordered">
<thead>
<tr>
<th>Features</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for data in features_data %}
<tr>
{% if data.feature_has_value != 'n' %}
<td>{{ data.feature_name }}</td>
<td><input type="text" name="{{ data.feature_name }}" id="{{ data.feature_name }}" placeholder="Enter {{ data.feature_name }}" class="form-control" required/></td>
{% else %}
<td>{{ data.feature_name }}</td>
<td>
<select id="{{ data.feature_name }}" name="{{ data.feature_name }}" class="form-control" required>
<option selected id="select" value="yes">Yes</option>
<option value="no">No</option>
</select>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
</form>
Now, the thing is how to insert this form data to the product features table( product_feature model at the starting of the question).
I want to insert multiple records in the product features a table with each record have it's feature_id, product_id & product_feature value.
I'm really confused about how to do this I'm new in Django development.