Commit ca00dce6 authored by Nate Brevin A. Que's avatar Nate Brevin A. Que

Updated the Homepage to include a link to add books and Implemented the 'Add...

Updated the Homepage to include a link to add books and Implemented the 'Add New Book' page using CreateView and configuring urls.py
parent 2988fa92
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
......@@ -14,6 +14,7 @@
a kid, either through movies or school. </h3><br><br>
{% endblock %}
{% block scripts %}
<a href="http://127.0.0.1:8000/books">Books</a>
<a href="http://127.0.0.1:8000/authors">Authors</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a><br>
<a href="/books/add">Add Book</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import homepage_view, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
from .views import (homepage_view, BooksListView, BooksDetailView, BooksCreateView,
AuthorListView, AuthorDetailView)
urlpatterns = [
path('home/', homepage_view, name='home'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='book-details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'),
path('authors/', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details'),
]
......
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
from .models import Books, Author
......@@ -11,23 +12,32 @@ def homepage_view(request):
class BooksListView(ListView):
model = Books
def get(self, request):
return render(request, 'bookshelf/books.html', {'nickname': "Brevin", 'books': self.model.objects.all()})
class BooksDetailView(DetailView):
model = Books
def get(self, request, pk):
return render(request, 'bookshelf/book_details.html', {'book': self.model.objects.get(pk=pk)})
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorListView(ListView):
model = Author
def get(self, request):
return render(request, 'bookshelf/authors.html', {'nickname': "Brevin", 'authors': self.model.objects.all()})
class AuthorDetailView(DetailView):
model = Author
def get(self, request, pk):
return render(request, 'bookshelf/author_details.html', {'author': self.model.objects.get(pk=pk)})
\ 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