1👍
Instead of a button
and a title
attr, I would use a form input
element with a type=hidden
. Reason being that it will post that data back to the server function that corresponds to that URL. Allowing you to save that data into a field of your choice.
As far as saving a list of strings
in a model field
, I would most likely just use a charfield
with a long max_length
. Then create a method on that model that splits by some chosen delimiter. In your case you already have a comma as your delimiter, so your model might look something like the following.
class MyModel(models.Model):
my_list_of_stuff = models.CharField(max_length=9999)
def my_list_of_stuff_split(self):
# this will return a list eg. `["foo, "bar", "pop" ...]`
return self.my_list_of_stuff.split(",")
Source:stackexchange.com