Python 让Django taggit在admin中显示标记的值

Python 让Django taggit在admin中显示标记的值,python,django,admin,django-taggit,Python,Django,Admin,Django Taggit,所以我想用django和django taggit制作一个简单的博客 这是我的模特 from django.db import models from django.db.models import permalink from taggit.managers import TaggableManager class Post(models.Model): title = models.CharField(max_length=100, unique=True) slug =

所以我想用django和django taggit制作一个简单的博客

这是我的模特

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

class Post(models.Model):
    title = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(max_length=100, unique=True)
    body = models.TextField()
    posted = models.DateField(db_index=True, auto_now_add=True)
    category = models.ForeignKey('Category')
    tag = TaggableManager()

    def __unicode__(self):
        return '%s' % self.title


class Category(models.Model):
    title = models.CharField(max_length=100, db_index=True)
    slug = models.SlugField(max_length=100, db_index=True)

    def __unicode__(self):
        return '%s' % self.title

    class Meta:
        verbose_name_plural = 'categories'
这是我的管理员

from django.contrib import admin
from .models import Post, Category


class PostAdmin(admin.ModelAdmin):
    exclude = ('posted',)
    list_display = ('title', 'category', 'tag', 'posted')
    list_filter = ('posted', 'tag')
    search_fields = ('title', 'body', 'category', 'tag')
    prepopulated_fields = {'slug': ('title',)}


class CategoryAdmin(admin.ModelAdmin):
    prepopulated_fields = {'slug': ('title',)}

admin.site.register(Post, PostAdmin)
admin.site.register(Category, CategoryAdmin)
现在在http://127.0.0.1:8000/admin/blog/post/ 在“标记”选项卡上显示。如何使其显示对象的标题?
提前感谢

这里说,您不能将其直接用于列表显示:

您可以像这样获得标签:

class PostAdmin(admin.ModelAdmin):    
    list_display=['get_tags']

    def get_tags(self, post):
        tags = []
        for tag in post.tags.all():
            tags.append(str(tag))
        return ', '.join(tags)

此处说明您不能将其直接用于列表显示:

您可以像这样获得标签:

class PostAdmin(admin.ModelAdmin):    
    list_display=['get_tags']

    def get_tags(self, post):
        tags = []
        for tag in post.tags.all():
            tags.append(str(tag))
        return ', '.join(tags)