Commit 2c6d6082 authored by Deokhyun Lee's avatar Deokhyun Lee

fixed view CBV and it displays the form correctly. Need to implement the submit button

parent 295a0ad7
......@@ -2,6 +2,7 @@
{% block title %}
Add New Book
{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
......
from django.views import View
from django.views.generic import ListView, DetailView
from django.views.generic import ListView, DetailView, CreateView
from django.shortcuts import render
from .models import Author, Books
from .forms import AddBookForm
......@@ -41,19 +41,7 @@ class BookDetailView(DetailView):
template_name = 'books/book_details.html'
context_object_name = 'book'
class BookAddListView(ListView):
template_name = 'add-book.html'
form_class = AddBookForm
def form_valid(self, form):
# Create a new book object with the form data
new_book = Books.objects.create(
title=form.cleaned_data['title'],
author=form.cleaned_data['author'],
publisher=form.cleaned_data['publisher'],
year_published=form.cleaned_data['year_published'],
ISBN=form.cleaned_data['ISBN'],
blurb=form.cleaned_data['blurb']
)
# Redirect the user to the list of books
return super().form_valid(form)
class BookAddListView(CreateView):
model = Books
fields = ['title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb']
template_name = "books/add-book.html"
\ 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