1👍
Code from a Howto Post
Template:
{% for tag in blogpost.get_tags %}
<a href="/blog/tag/{{tag}}" alt="{{tag}}" title="{{tag}}">{{tag}}</a>
{%endfor%}
Model:
from django.db import models
from tagging.fields import TagField
from tagging.models import Tag
class BlogPost(models.Model):
title = models.CharField(max_length=30)
body = models.TextField()
date_posted = models.DateField(auto_now_add=True)
tags = TagField()
def set_tags(self, tags):
Tag.objects.update_tags(self, tags)
def get_tags(self, tags):
return Tag.objects.get_for_object(self)
- [Django]-Create a facebook notification with Django package facepy : [15] (#15) This method must be called with an app access_token
- [Django]-UserWarning: Module _mysql was already imported from /usr/lib/pymodules/python2.6/_mysql.so
- [Django]-Use context processor only for specific application
0👍
form.tags
is defined in your form as a CharField
with a TextArea
widget. So when you access form.tags
you are accessing that field, not the underlying tags
model attribute (which I assume is some sort of m2m).
Without seeing your models it’s impossible to tell you exactly how to achieve what you’re trying to do, but the general idea is that you need to iterate over the tag objects, not the form field.
Source:stackexchange.com