7

This is a Model Class

class ModelName(models.Model):
  (...)
  pasta = TaggableManager(verbose_name=u'Pasta')

and a form template (normal :P )

{{form.as_p}}

I'd like to leave everything very clean and usefull. But result is a list of TaggedItem Object :( :

[<TaggedItem: id: 2 tagged with general >, <TaggedItem: id: 3  tagged with outer >]

Instead of something like

general, outer

How do it fashionably in Django?

Mohsen Safari
  • 6,669
  • 5
  • 42
  • 58
Luiz Carvalho
  • 1,549
  • 1
  • 23
  • 46

2 Answers2

8

Give a look at the code in: https://github.com/alex/django-taggit/blob/master/taggit/forms.py. You will find the widget used to render the tags. You can use it to render them correctly.

Example:

models.py

from django.db import models
from taggit.managers import TaggableManager


class Example(models.Model):
    name = models.CharField(max_length=20)    
    tags = TaggableManager()

forms.py

.models import Example
from django import forms
from taggit.forms import TagWidget


class ExampleForm(forms.ModelForm):

    class Meta:
        model = Example
        fields = ('name', 'tags',)
        widgets = {
            'tags': TagWidget(),
        }

I'd recommend you to check this answer too. django - django-taggit form

Community
  • 1
  • 1
Arthur Alvim
  • 1,044
  • 12
  • 23
  • I'm having the exact same issue but the solution in this answer has no effect for me. I'm using Django 1.7 and django-taggit==0.12.2. Any ideas? – Jack Nov 12 '14 at 20:12
0

I would use django-taggit-autosuggest as it offers better UI to the user.

Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156