2015-12-02 99 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

假設有一個自動完成和一個框,當自動完成覆蓋默認的許多多邊形顯示,看起來像一個多選框 –

回答