Commit 8c74acea authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

add-author is finally working

parent 38f32a2e
# Generated by Django 3.2 on 2023-04-25 09:39
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0004_alter_book_year_published'),
]
operations = [
migrations.AlterField(
model_name='book',
name='year_published',
field=models.DateField(default=datetime.datetime(2023, 4, 25, 17, 39, 19, 682230)),
),
]
......@@ -6,9 +6,10 @@
{% block content %}
<form id='addBook' action="/" method="post">
<form id='addAuthor' method="post">
{% csrf_token %}
<label for="firstName">First name:</label>
{{form.as_p}}
<!--<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>
......@@ -22,8 +23,9 @@
<input type="text" id="textField" name="ISBN"><br><br>
<label for="blurb">Blurb:</label>
<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">
<input type="text" id="textField" name="blurb" ><br><br>-->
<input type="submit" id="submitButton" value="Add Author">
</form>
{% endblock %}
\ No newline at end of file
......@@ -9,23 +9,6 @@
<form id="addBook" method="post">
{% csrf_token %}
{{ form.as_p }}
<!--<label for="title">Title:</label>
<input type="text" id="textField" name="title"><br><br>
<label for="author">Author:</label>
<select form="addBook" id="selectField" name='author'>
{% for author in object %}
<option value={{author}}>{{author}}</option>
{% endfor %}
</select>
<label for="publisher">Publisher:</label>
<input type="text" id="textField" name="publisher"><br><br>
<label for="yearPublished">Year published:</label>
<input type="date" id="dateField" name="yearPublished"><br><br>
<label for="ISBN">ISBN:</label>
<input type="text" id="textField" name="ISBN"><br><br>
<label for="blurb">Blurb:</label>
<textarea form="addBook" name="blurb"></textarea>
<input type="text" id="textField" name="blurb"><br><br>-->
<input type="submit" id="submitButton" value="Submit">
</form>
......
......@@ -29,7 +29,6 @@ class BooksAddView(CreateView):
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/")
......@@ -39,15 +38,37 @@ class BooksDetail(DetailView):
template_name = "bookshelf/book_detais.html"
class BooksEdit(UpdateView):
model = Book
template_name = "bookshelf/edit-book.html"
class AuthorView(ListView):
model=Author
template_name = "bookshelf/authors.html"
class AuthorAddView(CreateView):
model = Book
model = Author
fields='__all__'
template_name = "bookshelf/add-author.html"
def post(self, request, *args, **kwargs):
firstName = request.POST.get('first_name')
lastName = request.POST.get('last_name')
age = request.POST.get('age')
nationality = request.POST.get('nationality')
bio = request.POST.get('bio')
newObject = Author(first_name=firstName, last_name=lastName, age=age, nationality=nationality, bio=bio)
newObject.save()
return HttpResponseRedirect(str(newObject.get_absolute_url()) + "/details/")
class AuthorDetail(DetailView):
model=Author
template_name = "bookshelf/authors_details.html"
class AuthorEdit(UpdateView):
model=Author
template_name = "bookshelf/edit-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