Django 评论审核代码放在哪里?
我正在对现有网站实施库存 Django 注释。
我希望评论出现在多个应用程序和模型中,并且所有评论的行为都相同 - 即发送的电子邮件,加上其他位(监听“标志”信号并进行相应处理)
放置我的自定义主持人的最佳位置在哪里代码?
我知道我可以将模型的迭代器传递给寄存器函数 - 首先我将其放置在主应用程序的 __init__.py 模块中,如下所示:
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
)
但这给出了一个错误,指出 Model1
已注册。
我可能会将此代码重构为 comments_moderation.py
模块 - 但我应该将其包含在哪里?
或者最好的做法是在每个应用程序 models.py
文件中注册每个模型?
有没有使用注释的示例?
我只是通过反复试验才发现评论审核队列是如何工作的 - 有没有我错过的相关文档?
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 __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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
评论审核文档
一定要把代码放在一个自己的文件中,并将该文件放在“助手”应用程序中(每个项目都有一个)。
Comment Moderation Documentation
Definitely put the codein an own file and the file in a "helper" app (every project has one).