2015-11-25 82 views
1

我使用taggit,我想使用django taggit autosuggest自定義窗體(不,我不能使用ModelForm)。但是,無論我做什麼,我都無法在視圖中使自動暗示工作。Django標籤自動建議

這裏是我的(削減)模型:

from taggit_autosuggest.managers import TaggableManager 

class Ook(models.Model): 
    tags = TaggableManager() 

這裏是我的(減少)形式:

from taggit.forms import TagField 
from taggit_autosuggest.widgets import TagAutoSuggest 

class NewOokForm(forms.Form): 
    #m_tags = TagField() # This works but clearly has no autosuggestion. 
    m_tags = TagField(widget=TagAutoSuggest('taggit')) # Does not work! 

我得到的觀點沒有錯誤,只是沒有標籤建議任何責任。

我在做什麼錯?

我正在使用Django 1.8,這是1.8.7的問題時的最新版本。

+0

你會收到任何錯誤嗎? –

+0

@SandervanLeeuwen:沒有任何錯誤。 – Sardathrion

回答

2

(我不能寫註釋,所以...)爲了澄清情況:

如果有任何文件的丟失,你應該從存儲庫中獲得它。

(我們假定/靜是STATIC_URL在你的配置)

UPD:開始模型(使用的ModelForm)連接表時的工作:

from django.forms import ModelForm 


class OokForm(ModelForm): 
    class Meta: 
     model = Ook 
     fields = ['name', 'tags'] 

在views.py:

def OokView (request): 
    form = OokForm() 
    c = {'form': form} 
    return render(request,'ook_form.html', c) 

在ook_form.html:

<html> 
<head> 
    <!-- Be sure that there is no JS errors during loading --> 
    <script src="//code.jquery.com/jquery-1.10.1.min.js"></script> 
    <link href="/static/jquery-autosuggest/css/autoSuggest-grappelli.css" type="text/css" media="all" rel="stylesheet" /> 
    <script type="text/javascript" src="/static/jquery-autosuggest/js/jquery.autoSuggest.minified.js"> 
    </script> 
</head> 

<form action="/your-name/" method="post"> 
    {% csrf_token %} 
    {{ form }} 
    <input type="submit" value="Submit" /> 
</form> 

</body> 
+0

我使用的Django 1.8.7是當時最新的。 – Sardathrion

+0

'taggit_autosuggest/list /'返回我擁有的標籤的JSON。 – Sardathrion

+0

'js'和'css'都在那裏並且可以訪問。 – Sardathrion