我安装了Django标记。我阅读了教程和反汇编,它是如何工作的。 在我的模特中:
import tagging
class TaggingWidget(models.Model):
"""Widget for tagging."""
name = models.CharField(max_length = 50)
tagging.register(TaggingWidget)
当我尝试将小部件导入shell时,我有一个例外:
In [1]: from soapapp import models
---------------------------------------------------------------------------
AlreadyRegistered Traceback (most recent call last)
/home/user/workspace/soapbox/<ipython console> in <module>()
/home/user/workspace/soapbox/soapapp/models.py in <module>()
8
9
---> 10 tagging.register(TaggingWidget)
11
12
/home/user/Envs/env1/lib/python2.6/site-packages/tagging/__init__.pyc in register(model, tag_descriptor_attr, tagged_item_manager_attr)
37 if model in registry:
38 raise AlreadyRegistered("The model '%s' has already been "
---> 39 "registered." % model._meta.object_name)
40 if hasattr(model, tag_descriptor_attr):
41 raise AttributeError("'%s' already has an attribute '%s'. You must "
AlreadyRegistered: The model 'TaggingWidget' has already been registered.
有什么问题?我该怎么办?
答案 0 :(得分:8)
似乎是an open issue with django-tagging。一个简单的解决方法是
try:
tagging.register(TaggingWidget)
except tagging.AlreadyRegistered:
pass