Commit f02aa6b0 authored by Deokhyun Lee's avatar Deokhyun Lee

edit-author html can be accessed correctly and updating and redirecting works as intended.

parent 174b4b97
from django.urls import path from django.urls import path
from .views import HomeView, AuthorListView, AuthorDetailView, AuthorAddListView ,BookListView, BookDetailView, BookAddListView, BookEditView from .views import HomeView, AuthorListView, AuthorDetailView, AuthorAddListView, AuthorEditView ,BookListView, BookDetailView, BookAddListView, BookEditView
urlpatterns = [ urlpatterns = [
# for Home (landing page) # for Home (landing page)
...@@ -8,7 +8,7 @@ urlpatterns = [ ...@@ -8,7 +8,7 @@ urlpatterns = [
path('authors/', AuthorListView.as_view(), name='authors'), path('authors/', AuthorListView.as_view(), name='authors'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author_detail'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author_detail'),
path('authors/add', AuthorAddListView.as_view(), name="add_author" ), path('authors/add', AuthorAddListView.as_view(), name="add_author" ),
path('authors/<int:pk>/edit', AuthorEditView.as_view(), name='author_edit'),
# for Books page # for Books page
path('books/', BookListView.as_view(), name='books'), path('books/', BookListView.as_view(), name='books'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='book_detail'), path('books/<int:pk>/details', BookDetailView.as_view(), name='book_detail'),
......
...@@ -66,9 +66,9 @@ class BookEditView(UpdateView): ...@@ -66,9 +66,9 @@ class BookEditView(UpdateView):
form = AddBookForm(request.POST) form = AddBookForm(request.POST)
if form.is_valid(): if form.is_valid():
# onSave is called, the form will have essential data and this includes pk as well. # onSave is called, the form will have essential data and this includes pk as well.
new_book = form.save() update_book = form.save()
# pass the pk and redirect. # pass the pk and redirect.
return redirect('book_detail', pk = new_book.pk) return redirect('book_detail', pk = update_book.pk)
else: else:
return render(request, 'book_details.html', {'form': form}) return render(request, 'book_details.html', {'form': form})
...@@ -88,3 +88,18 @@ class AuthorAddListView(CreateView): ...@@ -88,3 +88,18 @@ class AuthorAddListView(CreateView):
return redirect('author_detail', pk = new_author.pk) return redirect('author_detail', pk = new_author.pk)
else: else:
return render(request, 'author_details.html', {'form': form}) return render(request, 'author_details.html', {'form': form})
class AuthorEditView(UpdateView):
model = Author
form_class = AddAuthorForm
template_name = 'authors/edit-author.html'
def post(self, request, pk):
form = AddAuthorForm(request.POST)
if form.is_valid():
# onSave is called, the form will have essential data and this includes pk as well.
update_author = form.save()
# pass the pk and redirect.
return redirect('author_detail', pk = update_author.pk)
else:
return render(request, 'author_details.html', {'form': form})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment