Answers for "use django taggit in template"

1

use django taggit in template

# models.py

from django.db import models
from taggit.managers import TaggableManager

class MyObject(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()

    tags = TaggableManager()

#template.html

{% for object in objects %}
    <h2>{{ object.title }}</h2>
    <p>{{ object.content }}</p>
    <ul>
        {% for tag in object.tags.all %}
            <li> {{ tag.name }} </li>
        {% endfor %}
    </ul>
{% endfor %}
Posted by: Guest on October-11-2020

Python Answers by Framework

Browse Popular Code Answers by Language