这是一个模型类
class ModelName(models.Model): (...) pasta = TaggableManager(verbose_name=u'Pasta')
和表单模板(正常:P)
{{form.as_p}}
我想把一切都非常干净和有用.
但结果是TaggedItem对象列表:(:
[<TaggedItem: id: 2 tagged with general >,<TaggedItem: id: 3 tagged with outer >]
而不是像
general,outer
Django如何时尚?
解决方法
看一下代码:
https://github.com/alex/django-taggit/blob/master/taggit/forms.py.您将找到用于呈现标记的小部件.您可以使用它来正确渲染它们.
例:
models.py
from django.db import models from taggit.managers import TaggableManager class Example(models.Model): name = models.CharField(max_length=20) tags = TaggableManager()
forms.py
.models import Example from django import forms from taggit.forms import TagWidget class ExampleForm(forms.ModelForm): class Meta: model = Example fields = ('name','tags',) widgets = { 'tags': TagWidget(),}
我建议你也检查这个答案.
django – django-taggit form