Commit 6d39344a authored by Trisha Angel Millena's avatar Trisha Angel Millena

Edited models.py and urls.py, Edited books.html and authors.html

parent 9cb3c5b3
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
...@@ -13,7 +15,7 @@ class Author(models.Model): ...@@ -13,7 +15,7 @@ class Author(models.Model):
return self.first_name + ' ' + self.last_name return self.first_name + ' ' + self.last_name
def get_absolute_url(self): def get_absolute_url(self):
return reverse('author-detail', kwargs = {'pk': self.pk},) return reverse("bookshelf:author-details", kwargs = {"pk": self.pk})
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length = 100) title = models.CharField(max_length = 100)
...@@ -27,4 +29,4 @@ class Books(models.Model): ...@@ -27,4 +29,4 @@ class Books(models.Model):
return self.title return self.title
def get_absolute_url(self): def get_absolute_url(self):
return reverse('book-detail', kwargs = {'pk': self.pk},) return reverse('bookshelf:book-details', kwargs = {'pk': self.pk})
\ No newline at end of file
...@@ -2,8 +2,13 @@ ...@@ -2,8 +2,13 @@
{% load static %} {% load static %}
{% block title %} {% endblock %} {% block title %}My Favorite Authors{% endblock %}
{% block content %} {% block content %}
<h1>Trisha's Favorite Authors</h1>
<ul>
{% for object in object_list %}
<li style = "list-style-type: circle">
</ul>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,8 +2,20 @@ ...@@ -2,8 +2,20 @@
{% load static %} {% load static %}
{% block title %} {% endblock %} {% block title %}My Favorite Authors{% endblock %}
{% block content %} {% block content %}
<h1>Trisha's Favorite Authors</h1>
<ul>
{% for object in object_list %}
<li>
<a href = '{{ object.get_absolute_url }}'>
{{ object.first_name }}
</a>
</li>
{% endfor %}
</ul>
<a href='/bookshelf/home/'>Home</a>
<a href='/bookshelf/authors/'>Books</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -16,4 +16,7 @@ ...@@ -16,4 +16,7 @@
{% endfor %} {% endfor %}
</ul> </ul>
<a href='/bookshelf/home/'>Home</a>
<a href='/bookshelf/authors/'>Authors</a>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import ( from .views import (
home, BookListView, BookDetailView, AuthorListView, AuthorDetailView home, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
) )
urlpatterns = [ urlpatterns = [
path('home/', home, name = 'home'), path('home/', home, name = 'home'),
path('books/', BookListView.as_view(), name = 'book-details'), path('books/', BooksListView.as_view(), name = 'books-list'),
path('books/<int:pk>/details', BookDetailView.as_view(), name = 'book-details'), path('books/<int:pk>/details', BooksDetailView.as_view(), name = 'book-details'),
path('authors/', AuthorListView.as_view(), name = 'author-list'), path('authors/', AuthorListView.as_view(), name = 'author-list'),
path('author/<int:pk>/details', AuthorDetailView.as_view(), name = 'author-details'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name = 'author-details'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -9,11 +9,11 @@ from .models import Author, Books ...@@ -9,11 +9,11 @@ from .models import Author, Books
def home(request): def home(request):
return render(request, 'bookshelf/home.html') return render(request, 'bookshelf/home.html')
class BookListView(ListView): class BooksListView(ListView):
model = Books model = Books
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
class BookDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.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