Cleaned Code

parent ae97c5a2
......@@ -16,7 +16,7 @@ class Author(models.Model):
return'{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse("Author_details", kwargs={"pk": self.pk})
return reverse("authordetails", kwargs={"pk": self.pk})
class Book(models.Model):
title=models.CharField(max_length=100)
......@@ -40,4 +40,4 @@ class Book(models.Model):
return'{}'.format(self.title)
def get_absolute_url(self):
return reverse("Book_details", kwargs={'pk': self.pk})
\ No newline at end of file
return reverse("bookdetails", kwargs={'pk': self.pk})
\ No newline at end of file
from django.urls import path
from . import views
from .views import (Home_Views, Authors_Details_Views,
Authors_Views, Book_Details_Views,
Books_Views)
from .views import (HomeViews, AuthorsDetailsViews,
AuthorsViews, BookDetailsViews,
BooksViews)
urlpatterns = [
path('home/', views.Home_Views, name='Home'),
path('authors/', Authors_Views.as_view(), name='Authors'),
path('books/', Books_Views.as_view(), name='Books'),
path('authors/<int:pk>/details/', Authors_Details_Views.as_view(), name='Author_details'),
path('books/<int:pk>/details/', Book_Details_Views.as_view(), name='Book_details'),
path('home/', views.HomeViews, name='home'),
path('authors/', AuthorsViews.as_view(), name='authors'),
path('books/', BooksViews.as_view(), name='books'),
path('authors/<int:pk>/details/', AuthorsDetailsViews.as_view(), name='authordetails'),
path('books/<int:pk>/details/', BookDetailsViews.as_view(), name='bookdetails'),
]
......@@ -4,33 +4,28 @@ from django.views.generic import ListView, DetailView
from .models import *
# Create your views here.
def Home_Views(request):
def HomeViews(request):
return render(request, 'home.html', {})
class Books_Views(ListView):
class BooksViews(ListView):
model = Book
template_name = "books.html"
context_object_name= 'Books_list'
context_object_name= 'books_list'
class Authors_Views(ListView):
class AuthorsViews(ListView):
model = Author
template_name = "authors.html"
context_object_name='Authors_list'
context_object_name='authors_list'
class Authors_Details_Views(DetailView):
class AuthorsDetailsViews(DetailView):
template_name = "author_details.html"
model = Author
def get_context_data(self, **kwargs):
context = super(Authors_Details_Views, self).get_context_data(**kwargs)
context = super(AuthorsDetailsViews, self).get_context_data(**kwargs)
context ['bookdetail'] = Book.objects.filter(author=self.get_object())
return context
class Book_Details_Views(DetailView):
class BookDetailsViews(DetailView):
template_name = "book_details.html"
model = Book
def get_context_data(self, **kwargs):
context = super(Book_Details_Views, self).get_context_data(**kwargs)
context ['authordetail'] = Author.objects.filter(book=self.get_object())
return context
\ No newline at end of file
model = Book
\ No newline at end of file
......@@ -11,10 +11,10 @@
<h2>{{object.bio}}</h2>
<h1>Books by {{object.first_name}} {{object.last_name}} I love:</h1>
{% for books in bookdetail %}
{% for details in bookdetail %}
<li>
<a href="{%url 'Book_details' books.pk %}">
{{books.title}}<br>
<a href="{%url 'bookdetails' details.pk %}">
{{details.title}}<br>
</li>
{%endfor%}
......
......@@ -9,10 +9,10 @@
</head>
<h1>Anchi's Favorite Authors:</h1>
{% for Author in Authors_list %}
{% for author in authors_list %}
<li>
<a href="{% url 'Author_details' Author.pk %}">
{{Author.first_name}} {{Author.last_name}}<br>
<a href="{% url 'author_details' author.pk %}">
{{author.first_name}} {{author.last_name}}<br>
</a>
</li>
{% endfor %}
......
......@@ -6,9 +6,7 @@
<title>{{object.title}}</title>
<h1>{{object.title}}</a></h1>
{% for Author in authordetail %}
<h2><a href="{%url 'Author_details' Author.pk %}">{{object.author}}</a></h2>
{% endfor %}
<h2><a href="{{object.author.get_absolute_url}}">{{object.author}}</a></h2>
<h2>{{object.publisher}}</h2>
<h2>{{object.year_published|date:'Y'}}</h2>
<h2>{{object.ISBN}}</h2>
......
......@@ -9,10 +9,10 @@
</head>
<h1>Anchi's Favorite Books:</h1>
{% for books in Books_list %}
{% for book in books_list %}
<li>
<a href="{%url 'Book_details' books.pk %}">
{{books.title}}<br>
<a href="{%url 'bookdetails' book.pk %}">
{{book.title}}<br>
</a>
</li>
......
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