added edit-author.html file and referenced it in models.py, urls.py, and views.py

parent ace513a0
......@@ -16,6 +16,9 @@ class Author(models.Model):
def get_absolute_url(self):
return reverse('bookshelf:author-detail', kwargs={'pk': self.pk})
def get_edit_url(self):
return reverse('bookshelf:edit-author', kwargs={'pk' : self.pk} )
class Book(models.Model):
......
......@@ -12,6 +12,7 @@
<ul><ul>{{object.age}}</ul></ul>
<ul><ul>{{object.nationality}}</ul></ul>
<ul><ul>{{object.bio}}</ul></ul>
<ul><button onclick="document.location='{{object.get_edit_url}}'">Edit Book</button></ul>
{%endblock%}
......
......@@ -12,7 +12,7 @@
<ul>{{object.year_published}}</ul>
<ul>{{object.ISBN}}</ul>
<ul>{{object.blurb}}</ul>
<ul><button onclick="document.location='{{object.get_edit_url}}'">HTML Tutorial</button></ul>
<ul><button onclick="document.location='{{object.get_edit_url}}'">Edit Author</button></ul>
{% endblock %}
{%block hyperlinks%}
......
from django.urls import path
from .views import home_view, BookListView, AuthorsListView, BookDetailsView, AuthorDetailsView, AddBookView, AddAuthorView, EditBookView
from .views import home_view, BookListView, AuthorsListView, BookDetailsView, AuthorDetailsView, AddBookView, AddAuthorView, EditBookView, EditAuthorView
urlpatterns = [
path('', home_view, name="My Favorite Books & Authors"),
......@@ -15,6 +15,7 @@ urlpatterns = [
path('books/<int:pk>/edit/', EditBookView.as_view(), name ="edit-book"),
path('authors/add/', AddAuthorView.as_view(), name ="add-author"),
path('authors/<int:pk>/edit/', EditAuthorView.as_view(), name ="edit-author"),
]
app_name = 'bookshelf'
\ No newline at end of file
......@@ -48,4 +48,9 @@ class AddAuthorView(CreateView):
class EditBookView(UpdateView):
model = Book
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
\ No newline at end of file
template_name = 'bookshelf/edit-book.html'
class EditAuthorView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-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