views:

100

answers:

1

I am trying to use the django-tagging in one of my project and run into some errors.

I can play with tags in the shell but couldn't assign them from admin interface.

What I want to do is add "tag" functionality to a model and add/remove tags from Admin interface.

Why is it the "tags" are seen by shell and not by "admin" interface? What is going on?

Model.py:

import tagging

class Department(models.Model):
    tags = TagField()

Admin.py:

class DepartmentAdmin(admin.ModelAdmin):
    list_display = ('name', 'tags') --> works
....
    fields = ['name', 'tags'] --> throws error

Error

    OperationalError at /admin/department/1/
    (1054, "Unknown column 'schools_department.tags' in 'field list'")

I looked at the docs and couldn't find further information Useful Tips Overview Txt

+4  A: 

The TagField requires an actual database column on your model; it uses this to cache the tags as entered. If you add a TagField to a model that already has a database table, you will need to add the column to the database table, just as with adding any other type of field. Either use a schema migration tool (like South or django-evolution) or run the appropriate SQL ALTER TABLE command manually.

Carl Meyer
I thought the tags are stored in 'tagging_taggeditem' as this will have a 1:n relationship with tagged item? I can see the tags are stored in this table referring the tags and the object_id. Will test it anyway.
lud0h
No it didn't change the eror.
lud0h
Tags are stored in tagging_taggeditem with a 1:n relationship, just as you say. Also, a TagField stores the tags as entered as a plain string in the database. Yes, it's denormalized, but that's how it works; you can check the code. And that error is clearly complaining that the schools_department table is missing the "tags" column, so if you're still getting the error, I have to think you didn't do the ALTER TABLE correctly.
Carl Meyer
I added the tags column in schools_department table but still get the same error. What I want to do is to add tags from the admin site. Could you give me some hints?
lud0h
Sorry, not really. All the code you have pasted looks fine, I have practically identical code running here (only difference is I generally use fieldsets rather than fields in the ModelAdmin, so I guess you could try that). The error still looks to me like MySQL complaining about a missing column in the table, but if you've addressed that? No idea.
Carl Meyer