Commit 8eddef72 authored by MJoshBen's avatar MJoshBen

Implemented Add Author and Updated Homepage Links

parent 7a0f156f
{% 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 %}
...@@ -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 %}
from django.urls import path from django.urls import path
from .views import homepage_view, BooksListView, BooksDetailView, BooksCreateView, AuthorListView, AuthorDetailView from .views import homepage_view, BooksListView, BooksDetailView, BooksCreateView, AuthorListView, AuthorDetailView, AuthorCreateView
urlpatterns = [ urlpatterns = [
path('home/', homepage_view, name='home'), path('home/', homepage_view, name='home'),
...@@ -9,6 +9,7 @@ urlpatterns = [ ...@@ -9,6 +9,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"
...@@ -38,5 +38,9 @@ class AuthorDetailView(DetailView): ...@@ -38,5 +38,9 @@ class AuthorDetailView(DetailView):
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)})
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.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