Commit 2f4a2e67 authored by Nate Brevin A. Que's avatar Nate Brevin A. Que

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

Updated the Homepage to include a link to add authors and Implemented the 'Add New Author' page using CreateView and configuring urls.py
parent ca00dce6
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Author">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
\ No newline at end of file
...@@ -17,4 +17,5 @@ ...@@ -17,4 +17,5 @@
<a href="/books">Books</a> <a href="/books">Books</a>
<a href="/authors">Authors</a><br> <a href="/authors">Authors</a><br>
<a href="/books/add">Add Book</a> <a href="/books/add">Add Book</a>
<a href="/authors/add">Add Author</a>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import (homepage_view, BooksListView, BooksDetailView, BooksCreateView, from .views import (homepage_view, BooksListView, BooksDetailView, BooksCreateView,
AuthorListView, AuthorDetailView) AuthorListView, AuthorDetailView, AuthorCreateView)
urlpatterns = [ urlpatterns = [
path('home/', homepage_view, name='home'), path('home/', homepage_view, name='home'),
...@@ -10,6 +10,7 @@ urlpatterns = [ ...@@ -10,6 +10,7 @@ urlpatterns = [
path('books/add/', BooksCreateView.as_view(), name='add-book'), path('books/add/', BooksCreateView.as_view(), name='add-book'),
path('authors/', AuthorListView.as_view(), name='authors-list'), path('authors/', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -29,6 +29,7 @@ class BooksCreateView(CreateView): ...@@ -29,6 +29,7 @@ class BooksCreateView(CreateView):
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
...@@ -40,4 +41,10 @@ class AuthorDetailView(DetailView): ...@@ -40,4 +41,10 @@ class AuthorDetailView(DetailView):
model = Author model = Author
def get(self, request, pk): def get(self, request, pk):
return render(request, 'bookshelf/author_details.html', {'author': self.model.objects.get(pk=pk)}) return render(request, 'bookshelf/author_details.html', {'author': self.model.objects.get(pk=pk)})
\ No newline at end of file
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
\ 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