Commit 109022c7 authored by Anthony Bicomong's avatar Anthony Bicomong

Lab04 specs: edits and adds

parent 6a5b0d67
...@@ -3,9 +3,9 @@ BICOMONG, Anthony P. ...@@ -3,9 +3,9 @@ BICOMONG, Anthony P.
CSCI 40C CSCI 40C
Lab 03: My Favorite Books and Authors Lab 03: My Favorite Books and Authors
I accomplished the specifications of this lab to the best of my own ability. I accomplished the specifications of this lab to the best of my own ability.
<sgd> Anthony Punzalan Bicomong, 28/03/2023 <sgd> Anthony Punzalan Bicomong, 25/04/2023
PROGRESS: LAB03:
-Setup local repository, venv, installations -Setup local repository, venv, installations
-Setup project: settings, urls -Setup project: settings, urls
-Setup bookshelf app: views, urls -Setup bookshelf app: views, urls
...@@ -16,4 +16,7 @@ PROGRESS: ...@@ -16,4 +16,7 @@ PROGRESS:
-Implement template functionality: project and app level -Implement template functionality: project and app level
BIG ISSUE ^^^ but got there in the end BIG ISSUE ^^^ but got there in the end
-Usable sites: Homepage, Books, Books details, Authors, Authors details -Usable sites: Homepage, Books, Books details, Authors, Authors details
-Screenshots, submissions: push to github -Screenshots, submissions: push to github
\ No newline at end of file
LAB04:
-implemented LAB04 specifications
\ No newline at end of file
from django.forms import ModelForm
from .models import Books, Author
class BooksForm(ModelForm):
class Meta:
model = Books
fields = '__all__'
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = '__all__'
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Add Author">
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Add Book">
</form>
{% endblock %}
\ No newline at end of file
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
<b>Age: </b> {{ object.age }} years old <br> <b>Age: </b> {{ object.age }} years old <br>
<b>Nationality:</b> {{ object.nationality }} <br> <b>Nationality:</b> {{ object.nationality }} <br>
<b>Biography:</b> {{ object.bio }} <br> <br> <b>Biography:</b> {{ object.bio }} <br> <br>
<input type = "Submit" value = "Edit Author" onclick="location.href='../{{ object.pk }}/edit/'">
<b>Books by {{ object }} I love:</b> <b>Books by {{ object }} I love:</b>
<ul> <ul>
{% for Books in object.booksquery.all %} {% for Books in object.booksquery.all %}
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
<b>ISBN: </b> {{ object.ISBN }} <br> <b>ISBN: </b> {{ object.ISBN }} <br>
<b>Blurb: </b>{{ object.blurb }} <br> <b>Blurb: </b>{{ object.blurb }} <br>
<input type = "Submit" value = "Edit Book" onclick="location.href='../{{ object.pk }}/edit/'">
{% endblock %} {% endblock %}
{% block table %} {% block table %}
......
{% extends 'base.html' %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes">
</form>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes">
</form>
{% endblock %}
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %}
{% block content %} {% block content %}
<h1>Welcome to Anthony's Database of Favorite Books and Authors!</h1> <h1>Welcome to Anthony's Database of Favorite Books and Authors!</h1>
...@@ -8,6 +7,12 @@ ...@@ -8,6 +7,12 @@
{% endblock %} {% endblock %}
{% block table %} {% block table %}
<tr>
<td><a href = '../books'>Books</a></td> <td><a href = '../books'>Books</a></td>
<td><a href = '../authors'>Authors</a></td> <td><a href = '../authors'>Authors</a></td>
{% endblock %} </tr>
<tr>
<td><a href = '../books/add'>Add Book</a></td>
<td><a href = '../authors/add'>Add Author</a></td>
</tr>
{% endblock %}
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path
from . import views from . import views
from .views import BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView
urlpatterns = [ urlpatterns = [
path('home/', views.HomeView, name = "home"), path('home/', views.HomeView, name = "home"),
...@@ -8,4 +9,12 @@ urlpatterns = [ ...@@ -8,4 +9,12 @@ urlpatterns = [
path('books/<int:pk>/details', views.BooksDetailView.as_view(), name="b_detail"), path('books/<int:pk>/details', views.BooksDetailView.as_view(), name="b_detail"),
path('authors/', views.AuthorListView.as_view(), name="authorlist"), path('authors/', views.AuthorListView.as_view(), name="authorlist"),
path('authors/<int:pk>/details', views.AuthorDetailView.as_view(), name="a_detail"), path('authors/<int:pk>/details', views.AuthorDetailView.as_view(), name="a_detail"),
path('books/add', BooksCreateView.as_view(), name = "add-book"),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name = "edit-book"),
path('authors/add', AuthorCreateView.as_view(), name = "add-author"),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name = "edit-author"),
] ]
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books from .models import Author, Books
def HomeView(request): def HomeView(request):
...@@ -22,3 +23,24 @@ class AuthorListView(ListView): ...@@ -22,3 +23,24 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
model = Author model = Author
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
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