I can get all tags' name one by one like this in template
{% for tag in blog.tags.all %}
<span class="label label-default">{{ tag.name }}</span>
{% endfor %}
And I can get a input from a form like this {{ form.tags }}
and it gives me:
<input id="id_tags" name="tags" type="text" value="xxx,y y y,zzz">
However I want to customize my input in my template like this
<input id="id_tags" class="form-control" maxlength="50" name="title" type="text" placeholder="tags" value="{{ form.tags }}">
How to set the input's value="{{ form.tags }}
"?
In your model you can do the following:
First you should have
tags = TaggableManager(blank = True)
the following will get all the tags and you can use get_tags in a list_field to get all tags for each record.
def get_tags(self):
tags = []
for tag in self.tags.all():
tags.append(str(tag))
return ', '.join(tags)
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