I'm trying to create an editable bootstrap table where each cell represents a json value. I've defined a Django Model with this JSONField (not the Postgres's one) This is my Model:
class Extracted_Tables(models.Model):
...
content = JSONField(blank=True, null=True)
My Template
<tbody>
{% for form in formset.forms %}
<tr>
{% for field in form %}
{% if field.is_hidden %}
<input type="hidden" >{{ field }}</input>
{% else %}
{% for k,v in field.value.items %}
<td>{{v}}</td>
{% endfor %}
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
This template renders the following HTML
<tr>
<td>Jamaica</td>
<td>Kingston</td>
<td>North America</td>
<td>11424</td>
<td>2500000</td>
<input type="hidden"><input type="hidden" name="formset_1-0-id" value="353" id="id_formset_1-0-id">
</tr>
To have a better idea on why it's not working: I've used a Django Model where my cells were this model's attributes. I had no problem editing the cells in this case as I was editing the model's fields This time, my cells are not the model's fields themselves: the only model field I have is a JSONField and I'm trying to edit the cells that are that json's values.
Model:
class Extracted_Variables(models.Model):
variables = models.CharField(max_length=500)
values = models.CharField(max_length=500)
The Template:
<tbody>
{% for form in formset.forms %}
<tr>
{% for field in form %}
{% if field.is_hidden %}
<input type="hidden" >{{ field }}</input>
{% else %}
<td>{{ field }}</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
The rendered template:
<tr>
<td><input type="text" name="form2-0-variables" value="variable 1" maxlength="500" class="form-control" id="id_form2-0-variables"></td>
<td><input type="text" name="form2-0-values" value="whatever" maxlength="500" class="form-control" id="id_form2-0-values"></td>
<input type="hidden"><input type="hidden" name="form2-0-id" value="1" id="id_form2-0-id">
</tr>
We see that the form was created by adding Ids and specific attributes based on the model fields whereas none of the that happened when I displayed the JSONField's values.
Should I try to create those fields manually while creating the form in the Template? Or what approach should I have here ?