Commit 43847e19 authored by Deokhyun Lee's avatar Deokhyun Lee

fixed the url pattern name

parent 75caf9b9
from django import forms from django import forms
from .models import Author, Books from .models import Books
class AddBookForm(forms.Form): class AddBookForm(forms.ModelForm):
class Meta: class Meta:
model = Books model = Books
fields = '__all__' fields = '__all__'
def save(self, commit=True): # def save(self, commit=True):
book = super().save(commit=False) # book = super().save(commit=False)
# Do any additional processing of the form data here # # Do any additional processing of the form data here
if commit: # if commit:
book.save() # book.save()
return book # return book
...@@ -6,9 +6,9 @@ urlpatterns = [ ...@@ -6,9 +6,9 @@ urlpatterns = [
path('home/', HomeView.as_view(), name='home'), path('home/', HomeView.as_view(), name='home'),
# for Authors page # for Authors page
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'),
# 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'),
path('books/add',BookAddListView.as_view(), name="add-book" ) path('books/add',BookAddListView.as_view(), name="add_book" )
] ]
\ No newline at end of file
...@@ -53,6 +53,6 @@ class BookAddListView(CreateView): ...@@ -53,6 +53,6 @@ class BookAddListView(CreateView):
# 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() new_book = form.save()
# pass the pk # pass the pk
return redirect('subject_detail', pk = new_book.pk) return redirect('book-details', pk = new_book.pk)
else: else:
return render(request, 'subject_detail.html', {'form': form}) return render(request, 'book_details.html', {'form': form})
\ No newline at end of file \ 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