Fixed all errors and updated readme. Finished coding!

parent 2390f98f
Izaac Daniel B. Muncal | 214138 | CSCI 40-E
Lab 3 - My Favorite Books and Authors
March 28, 2023
Lab 4 - My Favorite Books and Authors v2
April 27, 2023
I independently worked on my project. I only consulted to the given materials in the modules for help.
<sgd> Izaac Daniel B. Muncal March 28, 2023
\ No newline at end of file
<sgd> Izaac Daniel B. Muncal April 27, 2023
\ No newline at end of file
from django.db import models
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=255)
......@@ -11,6 +11,11 @@ class Author(models.Model):
def __str__(self):
return "{} {}".format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author-details', kwargs = {'pk':self.pk})
def get_update_url(self):
return reverse('bookshelf:author-edit', kwargs = {'pk':self.pk})
class Books(models.Model):
title = models.CharField(max_length=255)
......@@ -22,3 +27,10 @@ class Books(models.Model):
def __str__(self):
return "{}".format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('bookshelf:book-edit', kwargs={'pk': self.pk})
......@@ -2,7 +2,8 @@
{% load static %}
{% block title %} Add New Author {% endblock %}
{% block content %}
{% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
......
......@@ -2,7 +2,8 @@
{% load static %}
{% block title %} Add New Book {% endblock %}
{% block content %}
{% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
......
......@@ -7,7 +7,7 @@
<p>{{object.age}}</p>
<p>{{object.nationality}}</p>
<p>{{object.bio}}</p>
<a href="/bookshelf/author/{{author.pk}}/edit"><button>Edit Author</button></a><br><br>
<p><b>Books by {{object.first_name}} {{object.last_name}} I love:</b></p>
<ul>
{% for book in object.books_set.all %}
......
......@@ -10,6 +10,7 @@
<p>{{object.year_published}}</p>
<p>{{object.ISBN}}</p>
<p>{{object.blurb}}</p>
<a href="/bookshelf/books/{{books.pk}}/edit"><button>Edit Book</button></a><br><br>
<a href="/bookshelf/">Home</a>
<a href="/bookshelf/books/">Books</a>
......
......@@ -2,7 +2,8 @@
{% load static %}
{% block title %} Edit Author {% endblock %}
{% block content %}
{% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
......
......@@ -2,7 +2,8 @@
{% load static %}
{% block title %} Edit Book {% endblock %}
{% block content %}
{% block header %}{% endblock %}
{% block body %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
......
......@@ -5,11 +5,11 @@
{% block body %}
<p> I don't read books so these are the only books I have read so far.</p>
<a href="/bookshelf/books/">Books</a>-----------------------------------------
<a href="/bookshelf/author/">Authors</a>
<a href="/bookshelf/authors/">Authors</a>
<p>
<a href="/bookshelf/books/add">Add Book</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href = "/bookshelf/authors/add">Add Author</a>
</p>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import home_view, BooksView, BooksDetailView, AuthorView, AuthorDetailView, BookCreateView, BookUpdateView, AuthorCreateView, AuthorUpdateView
from .views import home_view, BooksView, BooksDetailView, AuthorView, AuthorDetailView, BookCreateView, BookUpdateView, \
AuthorCreateView, AuthorUpdateView
urlpatterns = [
path('', home_view, name='home'),
path('books/', BooksView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book-details'),
path('author/', AuthorView.as_view(), name='author'),
path('authors/', AuthorView.as_view(), name='author'),
path('author/<int:pk>/details/', AuthorDetailView.as_view(), name='author-details'),
path('books/add/', BookCreateView.as_view(), name='add-book'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('books/<pk>/edit/', BookUpdateView.as_view(), name='edit-book'),
path('authors/<pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
path('author/<pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
]
# This might be needed depending on your Django version
......
......@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.urls import reverse
from .models import Books, Author
......@@ -12,12 +13,12 @@ def home_view(request):
class AuthorView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
template_name = 'bookshelf/author.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
template_name = 'bookshelf/author_detail.html'
class BooksView(ListView):
......@@ -27,7 +28,7 @@ class BooksView(ListView):
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/books_details.html'
template_name = 'bookshelf/books_detail.html'
class AuthorCreateView(CreateView):
......
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