我建立了一个django自定义评论应用程序,使用django评论本身。我遵循https://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/这封信,我有两个问题,一个是我的自定义评论实例不给content_object。自定义django评论
所以,当我尝试以下方法我什么也没得到
c = CommentWithFile.object.get(id)=1
c.content_object
两个,我的意见没有采取上传我添加的自定义注释形式中的文件。
我想要做的另一件事是通过邮件通知某个特定用户的列表,每次有人对某个特定主题发表评论时,但我想在通知中添加一个网址或主题的标题评论发布了,我怎么能这样做?
我的自定义评论模型。
def upload_path(instance, filename):
return '/'.join(['uploads','comment_archives', filename])
class CommentWithFile(Comment):
comment_file = models.FileField(max_length=255, upload_to=upload_path,
blank=True, null=True)
notify = models.BooleanField(_("Notificar usuarios"))
@property
def fileobject(self):
if self.comment_file:
return FileObject(self.comment_file.path)
return None
我的自定义模型形式
class CommentFormWithFile(CommentForm):
comment_file = forms.FileField(label=_("Archivo"), required=False)
notify = form.BooleanField(label=_("Notificar usuarios"))
def get_comment_model(self):
# Use our custom comment model instead of the built-in one.
return CommentWithFile
def get_comment_create_data(self):
# Use the data of the superclass, and add in the title field
data = super(CommentFormWithFile, self).get_comment_create_data()
data['comment_file'] = self.cleaned_data['comment_file']
data['notify'] = self.cleaned_data['notify']
return data
而在初始化的.py
from apps.comments.models import CommentWithFile
from apps.comments.forms import CommentFormWithFile
def get_model():
return CommentWithFile
def get_form():
return CommentFormWithFile
我commentwithfile
from apps.comments.models import CommentWithFile
class CommentWithFileAdmin(admin.ModelAdmin):
pass
admin.site.register(CommentWithFile, CommentWithFileAdmin)
林全光照的管理文件g django 1.3.1,并有django通知为了通知用户的评论。
谢谢大家!
==== ==== UPDATE
下面是评论表单模板
{% load comments i18n %}
<form action="{% comment_form_target %}" method="post">{% csrf_token %}
{% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
{% for field in form %}
{% if field.is_hidden %}
<div>{{ field }}</div>
{% else %}
{% if field.errors %}{{ field.errors }}{% endif %}
<p
{% if field.errors %} class="error"{% endif %}
{% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
{% if field.label == 'Comentario' or field.label == 'Archivo' %}
{{ field }}
{% endif %}
</p>
{% endif %}
{% endfor %}
<div class="actions">
<input type="hidden" name="next" value="{{ request.path }}" />
<input type="submit" name="post" class="submit-post" value="{% trans "Post" %}" />
<input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" />
</div>
</form>
的继承人我如何使这种形式在其他模板
{% get_comment_form for archive as form %}
<h4>Comentar</h4>
<div class="main_comment" id="comment_form">
{% render_comment_form for archive %}
</div>
你可以发布你的模板和我们可能需要的一切来重现你的情况吗? TYIA :) – jpic 2012-02-20 17:50:11