我花了很多时间来修复它,但未成功,所以我希望在这里能得到您的帮助。 我想做的是我想通过评论表单在详细信息页面上添加评论,我知道我的 post 方法不完整,我应该在此方法中添加什么,这样我才能发布评论。 我正在使用ContentTypes框架使其可重用。
评论/模型.py
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=0" />
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
评论/forms.py
class GlobalComment(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
body = models.TextField()
published = models.DateTimeField(auto_now_add=True)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id') # by default it will take these two parameters if u dont provide
objects = GlobalCommentManager()
def __str__(self):
return self.body[:10]
myapp / views.py
class GlobalCommentForm(forms.Form):
content_type = forms.CharField(widget=forms.HiddenInput)
object_id = forms.IntegerField(widget=forms.HiddenInput)
body = forms.CharField(widget=forms.Textarea)