2015-12-02 48 views
0

我试图将django-autocomplete添加到标记字段,但它不起作用。我已经看过如何添加它,它包括创建自动完成文件。将django自动完成添加到标记字段

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

+0

你得到一个错误?还是说,当你保存模型时,它不会做它应该做的事情? – qasimalbaqali

+0

假设有一个自动完成和一个框,当自动完成覆盖默认的许多多边形显示,看起来像一个多选框 –

回答

相关问题