Django 评论审核代码放在哪里?

发布于 2024-08-14 16:24:28 字数 828 浏览 3 评论 0原文

我正在对现有网站实施库存 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有伤那来痛 2024-08-21 16:24:28

评论审核文档

一定要把代码放在一个自己的文件中,并将该文件放在“助手”应用程序中(每个项目都有一个)。

Comment Moderation Documentation

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文