这是一个模型类
class ModelName(models.Model):
(...)
pasta = TaggableManager(verbose_name=u'Pasta')和一个表单模板(normal :P )
{{form.as_p}}
我想让所有的东西都变得非常干净和有用。但结果是TaggedItem对象的列表:(:
[<TaggedItem: id: 2 tagged with general >, <TaggedItem: id: 3 tagged with outer >]

而不是像这样
general, outer它是如何在Django流行起来的?
发布于 2013-09-26 14:49:06
看一下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
发布于 2015-10-01 20:57:41
我会使用django-taggit-autosuggest,因为它为用户提供了更好的UI。
https://stackoverflow.com/questions/16091940
复制相似问题