how to use array in django
django, django-models, python
Solution
You may be interested in using a `CommaSeparatedIntegerField`.
If you've got a list of integers like this:
my_ints = [1,2,3,4,5]
and a model like this:
class MyModel(models.Model):
values = CommaSeparatedIntegerField(max_length = 200)
then you can save `my_ints` into a `MyModel` like this:
m = MyModel(values = ','.join(my_ints))
m.save()
Problem
I have a db table which has an integer array. But how can I add this field in my model? I tried writing it using `IntegerField` but on save it is giving error ``` int() argument must be a string or a number, not 'list ``` How can I add this field to my model? I am using this field in my views.py so I need to add it in my model. Any suggestions?