开发者

Where to put Django comments moderation code?

I am implementing the stock Django comments to an existing site.

I'd like comments to appear in multiple apps and models and have all the comments behave the same - i.e. an email sent, plus other bits (listening to 'flag' signals and dealing with accordingly)

Where's the best place to put my custom moderator code?

I understand that I can pass in an iterator of Models to the register function - at first I placed it inside the __开发者_StackOverflow社区init__.py module of my main app as so:

from django.contrib.comments.moderation import moderator, CommentModerator

from app.models import Model1
from app2.models import Model2
#.... etc

class MyCommentModerator(CommentModerator):
    email_notification = True
    enable_field = 'enable_comments'
    #...

moderator.register(
    [Model1,Model2,Model3,Model4,...],
    MyCommentModerator
)

But this gave an error saying that Model1 was already registered.

I would probably re-factor this code into a comments_moderation.py module - but where should I include it?

Or is it best practice to register each model inside each apps models.py file?

Are there any samples out there that use comments?

I only found out how the Comment moderation queue works by trial and error - are there any docs for this that I've missed?


Comment Moderation Documentation

Definitely put the codein an own file and the file in a "helper" app (every project has one).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜