Opened 8 years ago

Closed 8 years ago

#13368 closed (duplicate)

Cannot import Comment model in app models

Reported by: heylinus Owned by: nobody
Component: contrib.comments Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Cannot import Comment model of django.contrib.comments in app model.

# someapp/

from django.contrib.comments.models import Comment
class CommentScore(models.Model):
    comment = models.OneToOneField(Comment, primary_key=True)
# cannot use any manage command

$ ./ runserver 
Error: cannot import name Comment

$ ./ shell
Error: cannot import name Comment

$ ./ syncdb
Error: cannot import name Comment

# here is the trackback in a python terminal.

>>> from django.contrib.comments.models import Comment
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/django/contrib/comments/", line 4, in <module>
    from django.contrib.comments.models import Comment
  File "/Library/Python/2.6/site-packages/django/contrib/comments/", line 42, in <module>
    class Comment(BaseCommentAbstractModel):
  File "/Library/Python/2.6/site-packages/django/db/models/", line 162, in __new__
    new_class.add_to_class(, copy.deepcopy(field))
  File "/System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/", line 173, in deepcopy
    y = copier(memo)
  File "/Library/Python/2.6/site-packages/django/db/models/fields/", line 129, in __deepcopy__
    obj = copy.copy(self)
  File "/System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/", line 95, in copy
    return _reconstruct(x, rv, 0)
  File "/System/Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/", line 340, in _reconstruct
  File "/Library/Python/2.6/site-packages/django/db/models/fields/", line 146, in __setstate__
    self.default = self.model._meta.get_field_by_name([0].default
  File "/Library/Python/2.6/site-packages/django/db/models/", line 295, in get_field_by_name
    cache = self.init_name_map()
  File "/Library/Python/2.6/site-packages/django/db/models/", line 325, in init_name_map
    for f, model in self.get_all_related_m2m_objects_with_model():
  File "/Library/Python/2.6/site-packages/django/db/models/", line 402, in get_all_related_m2m_objects_with_model
    cache = self._fill_related_many_to_many_cache()
  File "/Library/Python/2.6/site-packages/django/db/models/", line 416, in _fill_related_many_to_many_cache
    for klass in get_models():
  File "/Library/Python/2.6/site-packages/django/db/models/", line 167, in get_models
  File "/Library/Python/2.6/site-packages/django/db/models/", line 64, in _populate
  File "/Library/Python/2.6/site-packages/django/db/models/", line 78, in load_app
    models = import_module('.models', app_name)
  File "/Library/Python/2.6/site-packages/django/utils/", line 35, in import_module
  File "/Library/Python/2.6/site-packages/djtest/testapp/", line 2, in <module>
    from django.contrib.comments.models import Comment
ImportError: cannot import name Comment

Change History (1)

comment:1 Changed 8 years ago by Ramiro Morales

Resolution: duplicate
Status: newclosed

I think this has already been reported in ticket 13366, Comment is a
model that inherits from an abstract base class that has fields

Note: See TracTickets for help on using tickets.
Back to Top