Skip to content

Instantly share code, notes, and snippets.

@sneeu
Last active October 7, 2015 09:27
Show Gist options
  • Save sneeu/3142821 to your computer and use it in GitHub Desktop.
Save sneeu/3142821 to your computer and use it in GitHub Desktop.
from django.shortcuts import get_object_or_404, render
from articles.forms import ArticleForm
from articles.models import Article
def article_edit(request, article_id):
article = get_object_or_404(Article, pk=article_id)
if request.method == 'POST':
form = ArticleForm(request.POST, instance=article)
if form.is_valid():
form.save()
return redirect('article_detail', article_id=article.pk)
else:
form = ArticleForm(instance=article)
context = {
'article': article,
'form': form,
}
return render(request, 'articles/article_edit.html', context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment