我试图弄清楚人们将如何写评论以及如何存储它是为谁写的和谁写的。我想看看为一个人 UserProfile.Comments 写的评论...
任何人都可以帮助我吗?
模型.PY
class UserProfile(models.Model):
comments = models.ForeignKey("Comments", null=True, blank=True)
class Comments(models.Model):
comment = models.CharField(max_length=500, null=False, blank=False)
who_wrote = models.ForeignKey(User)
VIEW.PY(我在这里卡住了)
def writecomment(request, username):
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
form.save(commit=False)
form.user = request.user
form.user_id = get_object_or_404(User, username=username).id
#frm = form.save()
usr = get_object_or_404(UserProfile, user = request.user)
usr.Comments = form #append??
usr.save()
else:
form = CommentForm(request.POST)
return render_to_response("writecomment.html", {"form": form}, context_instance=RequestContext(request))