Commit 210ed8fa authored by MJoshBen's avatar MJoshBen

Implemented Edit Author and Adjusted Author Details Links as well as URLs and Views

parent e82d0bf2
...@@ -5,16 +5,17 @@ ...@@ -5,16 +5,17 @@
<h1>{{ author }}</h1> <h1>{{ author }}</h1>
<h3>{{ author.age }}<br> <h3>{{ author.age }}<br>
{{ author.nationality }}<br> {{ author.nationality }}<br>
{{ author.bio }}</h3><br> {{ author.bio }}</h3>
<a href="/authors/{{ author.pk }}/edit"><input type="submit" value="Edit Book"></a><br>
<h3> Books by {{ author }} I love:</h3> <h3> Books by {{ author }} I love:</h3>
<ul> <ul>
{% for book in author.books_set.all %} {% for book in author.books_set.all %}
<li><a href="http://127.0.0.1:8000/{{ book.get_absolute_url }}">{{ book.title }}</a></li> <li><a href="{{ book.get_absolute_url }}">{{ book.title }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<a href="http://127.0.0.1:8000/home">Home</a> <a href="/home">Home</a>
<a href="http://127.0.0.1:8000/books">Books</a> <a href="/books">Books</a>
<a href="http://127.0.0.1:8000/authors">Authors</a> <a href="/authors">Authors</a>
{% endblock %} {% endblock %}
{% extends 'base.html' %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
{% block scripts %}
{% endblock %}
from django.urls import path from django.urls import path
from .views import homepage_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView, AuthorCreateView from .views import homepage_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView
urlpatterns = [ urlpatterns = [
path('home/', homepage_view, name='home'), path('home/', homepage_view, name='home'),
...@@ -10,7 +10,8 @@ urlpatterns = [ ...@@ -10,7 +10,8 @@ urlpatterns = [
path('books/<int:pk>/edit', BooksUpdateView.as_view(), name='edit-book'), path('books/<int:pk>/edit', BooksUpdateView.as_view(), name='edit-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') path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), nme='edit-author'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
...@@ -48,4 +48,8 @@ class AuthorCreateView(CreateView): ...@@ -48,4 +48,8 @@ class AuthorCreateView(CreateView):
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-author.html' template_name = 'bookshelf/add-author.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-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