added edit-bookpage and referenced it on views.py, models.py, and urls.py

parent 73bec87d
...@@ -39,4 +39,7 @@ class Book(models.Model): ...@@ -39,4 +39,7 @@ class Book(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('bookshelf:book-detail', kwargs={'pk': self.pk}) return reverse('bookshelf:book-detail', kwargs={'pk': self.pk})
def get_edit_url(self):
return reverse('bookshelf:edit-book', kwargs={'pk' : self.pk} )
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
{{object.title}} {{object.title}}
{% endblock %} {% endblock %}
{% block text%}
<ul><a href="{{object.author.get_absolute_url}}">{{object.author}}</a></ul>
<ul>{{object.publisher}}</ul>
<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>
{% endblock %}
{%block hyperlinks%} {%block hyperlinks%}
<ul><a href="{{object.author.get_absolute_url}}">{{object.author}}</a></ul> <ul><ul><a href="/home">Home</a>
<ul>{{object.publisher}}</ul> <a href="/books">Books</a>
<ul>{{object.year_published}}</ul> <a href="/authors">Authors</a></ul></ul>
<ul>{{object.ISBN}}</ul>
<ul>{{object.blurb}}</ul>
<br></br>
<ul><ul><a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a></ul></ul>
{%endblock%} {%endblock%}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import home_view, BookListView, AuthorsListView, BookDetailsView, AuthorDetailsView, AddBookView, AddAuthorView from .views import home_view, BookListView, AuthorsListView, BookDetailsView, AuthorDetailsView, AddBookView, AddAuthorView, EditBookView
urlpatterns = [ urlpatterns = [
path('', home_view, name="My Favorite Books & Authors"), path('', home_view, name="My Favorite Books & Authors"),
...@@ -12,6 +12,7 @@ urlpatterns = [ ...@@ -12,6 +12,7 @@ urlpatterns = [
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name ="author-detail"), path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name ="author-detail"),
path('books/add/', AddBookView.as_view(), name ="add-book"), path('books/add/', AddBookView.as_view(), name ="add-book"),
path('books/<int:pk>/edit/', EditBookView.as_view(), name ="edit-book"),
path('authors/add/', AddAuthorView.as_view(), name ="add-author"), path('authors/add/', AddAuthorView.as_view(), name ="add-author"),
] ]
......
...@@ -34,7 +34,6 @@ class AuthorDetailsView(DetailView): ...@@ -34,7 +34,6 @@ class AuthorDetailsView(DetailView):
return context return context
class AddBookView(CreateView): class AddBookView(CreateView):
model = Book model = Book
fields = '__all__' fields = '__all__'
...@@ -43,4 +42,10 @@ class AddBookView(CreateView): ...@@ -43,4 +42,10 @@ class AddBookView(CreateView):
class AddAuthorView(CreateView): class AddAuthorView(CreateView):
model = Author model = Author
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-author.html' template_name = 'bookshelf/add-author.html'
\ No newline at end of file
class EditBookView(UpdateView):
model = Book
fields = '__all__'
template_name = 'bookshelf/edit-book.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