djangodjango-formsdjango-taggit

Django tags auto suggest


I use taggit and I want to use django taggit autosuggest with a custom form (no, I cannot use a ModelForm). However, no matter what I do I cannot get the autosuggestion to work in the view.

Here is my (cut down) model:

from taggit_autosuggest.managers import TaggableManager

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

Here is my (cut down) form:

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!

I get no errors in the view, just no tag suggestions whatsoever.

What am I doing wrong?

I am using Django 1.8, the latest release at the time of the question which was/is 1.8.7.


Solution

  • (i can't write comments so...) To clarify situation:

    If any of files is missing, you should get it from repository.

    (We assume that /static is STATIC_URL in your config)

    Upd: Start to work when connecting Form with Model (using ModelForm ) :

    from django.forms import ModelForm
    
    
    class OokForm(ModelForm):
        class Meta:
            model = Ook
            fields = ['name', 'tags']
    

    in views.py:

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

    in 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>