How can i show multiple tag from tag model in django

Viewed 14

I'm beginner in Django/Python and I need to create a multiple select form. I know it's easy but I can't find any example. i use django-taggit.i want to select multiple tag in tag form with search engine . here is my forms.py

class QuestionForm(forms.ModelForm):
test = Tag.objects.order_by('name')
for tag in test:
    print(tag)
tags = forms.ModelMultipleChoiceField(label='Tags', queryset=Tag.objects.order_by('name'),widget=forms.SelectMultiple)

class Meta:
    model = Question
    fields = ['title', 'content','anonymous',"tags"]
    
    widgets = {
         'title' : forms.TextInput(attrs={'class':'form-control form-control form-control-lg '}),
         'content' : forms.Textarea(attrs={'class':'form-control'}),
        #  'tags' : forms.Textarea(attrs={'class':'form-control'}),
         
    }

form.html

  {{form.tags}}

i want this

enter image description here

1 Answers

THere is no link with python/django. Your problem concerns html and js page. Your {{form.tags}} render html, you just have to use js and CSS to display as you want the html generated

You have to write your code or using a js lib like magicsuggest : http://nicolasbize.com/magicsuggest/examples.html

Related