tag template django code example

Example 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 %}

Example 2: template tag django

if create_time >= last_date: