Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created March 19, 2014 10:48
Show Gist options
  • Save sneeu/9639323 to your computer and use it in GitHub Desktop.
Save sneeu/9639323 to your computer and use it in GitHub Desktop.
# URLs:
# url('new/$', author_edit, name='author_new')
# url('(?P<author_id>\d+)/$', author_edit, name='author_edit')
def author_edit(request, author_id=None):
author = None
if author_id:
author = Author.objects.get(pk=author_id)
if request.POST:
form = AuthorForm(request.POST, instance=author)
if form.is_valid():
form.save()
return redirect('author_list')
else:
form = AuthorForm(instance=author)
return render(request, 'author_edit.html', {'form': form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment