Commit 38f32a2e authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

add-book is working

parent 4dc16d41
......@@ -2,18 +2,18 @@
{% block title %} Add new Author {% endblock %}
{% block additional %} Add new Author {% endblock %}
{% block content %}
<form action="/" method="post">
<form id='addBook' action="/" method="post">
{% csrf_token %}
<label for="title">Title:</label>
<input type="text" id="textField" name="title"><br><br>
<label for="author">Author:</label>
<select id="selectField" name='author'>
{% for author in object_list %}
<option value={{ author }}>{{ author }}</option>
{% endfor %}
</select>
<label for="firstName">First name:</label>
<input type="text" id="textField" name="firstName"><br><br>
<label for="lastName">Last name:</label>
<input type="text" id="textField" name="lastName"><br><br>
<label for="age">Age:</label>
<input type="number" id="textField" name="age"><br><br>
<label for="publisher">Publisher:</label>
<input type="text" id="textField" name="publisher"><br><br>
<label for="yearPublished">Year published:</label>
......@@ -21,9 +21,9 @@
<label for="ISBN">ISBN:</label>
<input type="text" id="textField" name="ISBN"><br><br>
<label for="blurb">Blurb:</label>
<input type="text" id="textField" name="blurb"><br><br>
<input type="submit" id="submitButton" value="Submit">
<textarea name="blurb" form='addBook' rows=50 cols=50></textarea>
<input type="text" id="textField" name="blurb" ><br><br>
<input type="submit" id="submitButton" value="Add book">
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,16 +2,19 @@
{% block title %} Add new Book {% endblock %}
{% block additional %} Add new Book {% endblock %}
{% block content %}
<form action="/" method="post">
<form id="addBook" method="post">
{% csrf_token %}
<label for="title">Title:</label>
{{ form.as_p }}
<!--<label for="title">Title:</label>
<input type="text" id="textField" name="title"><br><br>
<label for="author">Author:</label>
<select id="selectField" name='author'>
{% for author in object_list %}
<option value={{ author }}>{{ author }}</option>
<select form="addBook" id="selectField" name='author'>
{% for author in object %}
<option value={{author}}>{{author}}</option>
{% endfor %}
</select>
<label for="publisher">Publisher:</label>
......@@ -21,7 +24,8 @@
<label for="ISBN">ISBN:</label>
<input type="text" id="textField" name="ISBN"><br><br>
<label for="blurb">Blurb:</label>
<input type="text" id="textField" name="blurb"><br><br>
<textarea form="addBook" name="blurb"></textarea>
<input type="text" id="textField" name="blurb"><br><br>-->
<input type="submit" id="submitButton" value="Submit">
</form>
......
from django.shortcuts import render
from django.http.response import HttpResponseRedirect
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Book
def homeView(request):
return render(request, 'home.html')
......@@ -14,10 +16,23 @@ class BooksView(ListView):
class BooksAddView(CreateView):
model = Author
model = Book
fields='__all__'
template_name = "bookshelf/add-book.html"
def post(self, request, *args, **kwargs):
title = request.POST.get('title')
author = request.POST.get('author')
publisher = request.POST.get('publisher')
yearPublished = request.POST.get('year_published')
ISBN = request.POST.get('ISBN')
blurb = request.POST.get('blurb')
s = Book(title=title, author=Author.objects.get(pk=author), publisher=publisher, year_published=yearPublished, ISBN=ISBN, blurb=blurb)
newUrl = s.save()
return HttpResponseRedirect(str(s.get_absolute_url()) + "/details/")
class BooksDetail(DetailView):
model = Book
......@@ -28,7 +43,7 @@ class AuthorView(ListView):
model=Author
template_name = "bookshelf/authors.html"
class AuthorAddView(ListView):
class AuthorAddView(CreateView):
model = Book
template_name = "bookshelf/add-author.html"
......
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