I have an a type of ArrayField
in a model. The backend in a list of suggested elements for my_list
automatically. However, the user then needs to update this list as needed. The model looks like this:
class my_model(models.Model):
my_list = ArrayField(
models.CharField(max_length=10)
)
The problem is that when my_list
is rendered in the template is a single html input tag with a comma separated list. For example a,b,c,d
.
My question is two fold. How can I get the templating language to display the comma separated list so that each element has their own html input box. Moreover, the harder thing that I am struggling with is how to make it so that these elements will be saved back to the model back as an array.
My current thinking is to hack the front-end with javascript. But is there a better way to do it with Django?
I do not know what is your exact goal but it can be something like this:
{% for element in my_list %}
<div> {{element}} </div> <!--any html tag which you desire-->
{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With