Commit a1966700 authored by Ysobel Vera's avatar Ysobel Vera

Edited README text, added the add-book and add-author html files, and edited the app views.py

+Edited README.text to updated information.
+created the add-book and add-author html files
+edited the app's views.py file to add create views for Add Book and Add Author
parent 3ed479e2
...@@ -3,9 +3,9 @@ Maria Ysobel Lourdes A. Vera ...@@ -3,9 +3,9 @@ Maria Ysobel Lourdes A. Vera
BS CS-DGDD BS CS-DGDD
CSCI 40-F CSCI 40-F
Lab 03: My Favorite Books and Authors Lab 04: My Favorite Books and Authors v2
March 28,2023 April 25,2023
This lab has been truthfully completed by me. This lab has been truthfully completed by me.
<sgd> Maria Ysobel Lourdes A. Vera, March 28,2023 <sgd> Maria Ysobel Lourdes A. Vera, April 25,2023
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form action="/" method="post">
{% csrf_token %}
{{ form.as_p }}
<!--<label for="title">First Name:</label>
<input type="text" name="first_name" id="first_name"><br>
<label for="author">Last Name:</label>
<input type="text" name="last_name" id="last_name"><br>
<label for="age">Age:</label>
<input type="number" name="age" id="age"><br>
<label for="nationality">Nationality:</label>
<input type="text" name="nationality" id="nationality"><br>
<label for="bio">Bio:</label>
<input type="textarea" name="bio" id="bio"><br><br>-->
<input type="submit" value="Add Author">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form action="/" method="post">
{% csrf_token %}
{{ form.as_p }}
<!--<label for="title">Title:</label>
<input type="text" name="title" id="title"><br>
<label for="author">Author:</label>
<select id = "selectField" name="author">
{% for author in object.authors.all %}
<option value = {{ author }}>{{ author }}</option>
{% endfor %}
<input type="text" name="author" id="author"><br>
<label for="publisher">Publisher:</label>
<input type="text" name="publisher" id="publisher"><br>
<label for="publisher">Year Published:</label>
<input type="number" name="year_published" id="year_published"><br>
<label for="ISBN">ISBN:</label>
<input type="number" name="ISBN" id="ISBN"><br>
<label for="blurb">Blurb:</label>
<input type="textarea" name="blurb" id="blurb"><br><br>-->
<input type="submit" value="Add Book">
</form>
{% endblock %}
\ No newline at end of file
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
<a href="/books">Books</a> <a href="/books">Books</a>
<a href="/authors">Authors</a> <a href="/authors">Authors</a>
</div> </div>
<div>
<a href="/books/add/">Add Book</a>
<a href="/authors/add/">Add Author</a>
</div>
{% endblock %} {% endblock %}
from django.urls import path from django.urls import path
from .views import home_view, BooksDetailView, BooksView, AuthorsView, AuthorDetailsView from .views import home_view, BooksDetailView, BooksView, AuthorsView, AuthorDetailsView, BookCreateView, AuthorCreateView
urlpatterns = [ urlpatterns = [
path('home/', home_view, name='index'), path('home/', home_view, name='index'),
...@@ -8,6 +8,8 @@ urlpatterns = [ ...@@ -8,6 +8,8 @@ urlpatterns = [
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'), path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/', AuthorsView.as_view(), name='authors'), path('authors/', AuthorsView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name='author-detail'), path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name='author-detail'),
path('books/add/', BookCreateView.as_view(), name='add-book'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
...@@ -2,6 +2,7 @@ from django.shortcuts import render ...@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from .models import Books, Author from .models import Books, Author
def home_view(request): def home_view(request):
...@@ -22,3 +23,15 @@ class AuthorsView(ListView): ...@@ -22,3 +23,15 @@ class AuthorsView(ListView):
class AuthorDetailsView(DetailView): class AuthorDetailsView(DetailView):
model = Author model = Author
template_name = "bookshelf/author_details.html" template_name = "bookshelf/author_details.html"
class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = "bookshelf/add-book.html"
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = "bookshelf/add-author.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