def ctt_altacomentario(context, noticia): request = context.get('request') if request.method == 'POST': form = ComentarioForm(request.POST) if form.is_valid(): form.save() noticia = Noticia.objects.get(pk=noticia.pk) form = ComentarioForm() else: form = ComentarioForm(initial={'fecha': date.today(), 'noticia': context['noticia'], 'usuario': User.objects.get(pk=1)}) return { 'form' : form, 'noticia' : noticia, 'categorias' : CategoriasMixin.categorias()}
def post(self, request, *args, **kwargs): idnoticia = self.kwargs.get('idnoticia', None) if not idnoticia is None: form = ComentarioForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('noticia', args={idnoticia})) else: return HttpResponseRedirect(reverse('noticia', {'noticia': Noticia.objects.get(pk=idnoticia), 'comentarioForm': form, 'categorias': CategoriasMixin.categorias()})) #return render(request, 'djEj1/noticia.html', {'noticia': Noticia.objects.get(pk=idnoticia), 'comentarioForm': form, 'categorias': CategoriasMixin.categorias()}) return HttpResponseRedirect(reverse('noticias'))