Django 评论: 想要删除用户 URL,而不是扩展模型。怎样做?
我完全理解有关在 Django 中扩展评论应用程序的文档,并且真的很想坚持使用自动功能但是...
在当前的应用程序中,我绝对没有使用“URL” ”与评论一起提交。
作为对默认设置的最小侵入,如何防止此字段与评论表单一起显示?
使用 Django 1 或 Trunk,以及尽可能多的通用/内置插件(通用视图、默认注释设置等。到目前为止,我只有一个通用视图包装器)。
I'm totally understanding the documentation on expanding the Comments app in Django, and really would like to stick with the automatic functionality but...
In the current app, I have absolutely no use for an "URL" to be submitted along with a comment.
Being minimally invasive of the default setup, how can I prevent this field from showing up with the comment form?
Using Django 1, or Trunk, and as many generic/built-ins as possible (generic views, default comments set up, etc. I have only a single generic view wrapper so far).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于某种原因我无法评论 SmileyChris 的帖子,所以我将其发布在这里。但是,我仅使用 SmileyChris 的回复就遇到了错误。您还必须覆盖 get_comment_create_data 函数,因为 CommentForm 将查找您删除的那些 Post 键。这是我删除三个字段后的代码。
这是您要覆盖的函数
I can't comment onto SmileyChris' post for some reason, so I am going to post it here. But, I ran into errors using just SmileyChris' response. You also have to overwrite the get_comment_create_data function because CommentForm is going to look for those Post keys that you removed. So here's my code after I removed three fields.
This is the function that you are overwriting
这在自定义评论框架下有详细记录。
您的应用程序将使用的所有内容是
get_form
,返回CommentForm
的子类,并弹出 url 字段。像这样的东西:This is well documented under customizing the comments framework.
All your app will use is
get_form
, returning a subclass of theCommentForm
with the url field popped. Something like:我的快速而肮脏的解决方案:我将“电子邮件”和“网址”字段设置为隐藏字段,并使用任意值来消除“此字段为必填”错误。
它并不优雅,但速度很快,而且我不必子类化 CommentForm。所有添加评论的工作都在模板中完成,这很好。它看起来像这样(警告:未经测试,因为它是我实际代码的简化版本):
My quick and dirty solution: I made the the 'email' and 'url' fields hidden fields, with an arbitrary value to get rid of 'this field is required' errors.
It's not elegant, but it's quick and I didn't have to subclass CommentForm. All the work of adding comments was done in the template, which is nice. It looks like this (warning: not tested, since it's a simplified version of my actual code):