Пример #1
0
 def post(self, request, id):
     self.init(id)
     newcomment = Comment()
     newcomment.text = request.POST['text']
     newcomment.pub_date = timezone.datetime.now()
     newcomment.author = request.user
     newcomment.save()
     instance.comments.add(newcomment)
     return redirect(self.selfurl, instance.pk)
Пример #2
0
def detail(request, cf_id):
	try:
		confession = Confession.objects.get(pk=cf_id)
	except Confession.DoesNotExist:
		return redirect('homeconfession') #NOT DONE YET
	comments = Comment.objects.filter(confession=confession)
	if request.method == 'GET':
		return render(request, 'confession/details.html', {'confession': confession, 'comments': comments})
	elif request.method == 'POST':
		if request.POST['text']:
			newcomment = Comment()
			newcomment.text = request.POST['text']
			newcomment.pub_date = timezone.datetime.now()
			newcomment.author = request.user
			newcomment.confession = Confession.objects.get(pk=cf_id)
			newcomment.save()
			return redirect('detailconfession', confession.pk)
		else:
			return render(request, 'confession/details.html', {'confession': confession, 'error': 'You can\'t leave a blank comment', 'comments': comments})