def edit_article(request, *args, **kwargs): id_url = kwargs["id"] selected_article = Article.objects.get(id=id_url) if request.method == 'POST': form = Articleform(request.POST, request.FILES, instance=selected_article) if form.is_valid(): # article = Article.objects.get(start=True) # article.start = False # article.save() selected_article.title = request.POST.get('title') selected_article.text = request.POST.get('text') if request.FILES.get('image'): selected_article.image = request.FILES.get('image') # selected_article.author = request.user selected_article.category = Category.objects.get( slug=request.POST.get('category')) selected_article.status = request.POST.get('status') form.save() messages.success(request, u"L'article sur {} a été mise à jour.".format(selected_article.title)) return HttpResponseRedirect('/admin/') else: form = Articleform(instance=selected_article) return render(request, 'administration/add_article.html', {'form': form, 'page_title': _("Editing Article")})
def add_article(request): c = {'settings': settings, 'page_title': _("Adding article")} if request.method == 'POST': form = Articleform(request.POST, request.FILES) if form.is_valid(): article = form.save(commit=False) article.author = request.user article.save() messages.success(request, _("Article added")) return HttpResponseRedirect('/admin/') else: form = Articleform() c.update({'form': form}) return render(request, 'administration/add_article.html', c)