문제

I wanted to add a StackOverflow-style tag input to a blog model of mine. This is a model that has a lot of data already in it.

class BlogPost(models.Model):
    # my blog fields

try:
    tagging.register(BlogPost)
except tagging.AlreadyRegistered:
    pass

I thought that was all I needed so I went through my old database of blog posts (this is a newly ported blog) and copied the tags in. It worked and I could display tags and filter by tag.

However, I just wrote a new BlogPost and realise there's no tag field there.

Reading the documentation (coincidentally, dry enough to be used as an antiperspirant), I found the TagField. Thinking this would just be a manager-style layer over the existing tagging register, I added it. It complained about there not being a Tag column.

I'd rather not denormalise on tags just to satisfy create an interface for inputting them. Is there a TagManager class that I can just set on the model?

    tags = TagManager() # or somesuch
도움이 되었습니까?

해결책

Did you try using TagField() in the model instead of registering the model?

from tagging.fields import TagField

class BlogPost(models.Model):
    # ...
    tags = TagField()

다른 팁

셸 명령을 효과적으로 실행하고 경로의 공백으로 트립되어 있습니다.인수를 인용하는 대신, 이렇게하는 것이 클리너입니다.

import subprocess
subprocess.call([ "gnome-open", nameList[row] ] )
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top