将django autocomplete添加到tags字段

时间:2015-12-02 12:04:12

标签: python django django-autocomplete-light

我尝试将django-autocomplete添加到代码字段,但它不起作用。我已经查看了如何添加它,它包括制作自动完成文件。

class Tag(models.Model):
    name = models.CharField(max_length=20, blank=True)

    class Meta:
        ordering = ['name',]

    def __unicode__(self):
        return self.name


class Article(BaseItemModel):
    area = TreeForeignKey(Area, blank=True, null=True,)
    categories = TreeManyToManyField(Category)
    #imdb_id = models.CharField(max_length=255, blank=True, help_text="Used only for Series and Movie Reviews")
    tags = models.ManyToManyField(Tag, blank=True, null=True)
    parent = models.ForeignKey(Movie, blank=True, verbose_name='Parent Movie', null=True, help_text="Used only for Series and Movie Reviews")
    rating = models.IntegerField(blank=True, default=0)
    editor_pick = models.BooleanField(default=False,)
    author = models.CharField(max_length=255, blank=True,)
    html = RichTextUploadingField(blank=True, null=True,)
    #html_edited = RichTextUploadingField(blank=True, null=True,)


class ArticleAdmin(CommonAdmin):
    form = autocomplete_light.modelform_factory(Article)
    list_display = [
        'name',
        'categories_display',
        'modified_by',
        'created_by',
        'modified',
        'created',
        'visible',
        'editor_pick',
        'rating',
        'tags',
    ]
    list_filter = ['modified', 'created', 'visible','editor_pick']
    list_editable = ['visible','editor_pick']
    #filter_horizontal = ('tags',)
    #list_filter = ('categories',)
    excludes = ['sortorder',]
    inlines = [
        HotItemInline,
        ArticleImageInline,
        ArticleYoutubeVideoInline,
        #RelatedArticleInline
    ]

import autocomplete_light

from articles.models import *

autocomplete_light.register(Article, search_fields=('name','tags'),
    autocomplete_js_attributes={'placeholder': 'article name ..'})

它不适用于我使用自动完成版本2.0.2的标记字段

1 个答案:

答案 0 :(得分:0)