Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django tagging: "already registered" exception

I installed Django tagging. I read the tutorial and disassemble, how it works. In my models:

import tagging

class TaggingWidget(models.Model):
    """Widget for tagging."""
    name = models.CharField(max_length = 50)


tagging.register(TaggingWidget)

When I tried import the widget to shell I have an exception:

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.

What is wrong? What should I do?

like image 397
I159 Avatar asked Feb 23 '23 22:02

I159


1 Answers

Seems to be an open issue with django-tagging. A simple workaround is

try:
    tagging.register(TaggingWidget)
except tagging.AlreadyRegistered:
    pass
like image 141
Ismail Badawi Avatar answered Feb 26 '23 20:02

Ismail Badawi