Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django comment moderation error: AlreadyModerated at /

Tags:

python

django

I'm trying to add the comments framework to a weblog I'm creating in Django. Adding the comments system appears to be working fine until I attempt to enable comment moderation.

I add the following code to my models.py as per the instructions on the above link. My model is called Post which represents a post in the weblog.

class PostModerator(CommentModerator):
    email_notification = False
    enable_field = 'allow_comments'

moderator.register(Post, PostModerator)

If I attempt to preview the site I get error AlreadyModerated at / with the exception The model 'post' is already being moderated. I have no idea why I'm getting this error as I have only just enabled comments and am not sure why Post would already be moderated.

like image 457
Will Avatar asked Feb 26 '23 15:02

Will


1 Answers

Just had a similar problem today, but I think I've solved it :) In my case the issue was that django was loading models.py twice and therefore trying to register the model for comment moderation twice as well. I fixed this by modifying the code from:

moderator.register(Post, PostModerator)

to:

if Post not in moderator._registry:
    moderator.register(Post, PostModerator)
like image 132
Monika Sulik Avatar answered Mar 07 '23 04:03

Monika Sulik