Commit 01c3e88f authored by Cheska Hung's avatar Cheska Hung

Edit Book and edit Author added

parent 3bd82eb4
...@@ -3,7 +3,7 @@ from django.urls import path ...@@ -3,7 +3,7 @@ from django.urls import path
from . import views from . import views
from .views import (HomeView, BooksListView, BooksDetailView, from .views import (HomeView, BooksListView, BooksDetailView,
AuthorListView, AuthorDetailView, BookAddView, AuthorListView, AuthorDetailView, BookAddView,
AuthorAddView) AuthorAddView, AuthorEditView, BookEditView)
urlpatterns = [ urlpatterns = [
...@@ -14,9 +14,12 @@ urlpatterns = [ ...@@ -14,9 +14,12 @@ urlpatterns = [
path('authors/', AuthorListView.as_view(), name='author'), path('authors/', AuthorListView.as_view(), name='author'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), path('authors/<int:pk>/details', AuthorDetailView.as_view(),
name='author-detail'), name='author-detail'),
path('books/add', BookAddView.as_view(), name='author'), path('books/add', BookAddView.as_view(), name='bookdetailview'),
path('authors/add', AuthorAddView.as_view(), name='author'), path('authors/add', AuthorAddView.as_view(), name='authordetailview'),
path('authors/<int:pk>/edit/', AuthorEditView.as_view(),
name='authorupdateview'),
path('books/<int:pk>/edit/', BookEditView.as_view(),
name='bookupdateview')
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
...@@ -3,6 +3,7 @@ from django.views.generic.detail import DetailView ...@@ -3,6 +3,7 @@ from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views import generic from django.views import generic
from .models import Books from .models import Books
from django.urls import reverse
from .models import Author from .models import Author
...@@ -38,9 +39,19 @@ class BookAddView(generic.CreateView): ...@@ -38,9 +39,19 @@ class BookAddView(generic.CreateView):
template_name = 'add-book.html' template_name = 'add-book.html'
def get_success(self): def get_success(self):
return reverse('bookshelf:bookdetailview', kwarg={'pk': self.object.id}, return reverse('bookshelf:books-detail', kwarg={'pk': self.object.id},
current_app=self.request.resolver_match.namespace) current_app=self.request.resolver_match.namespace)
class BookEditView(generic.UpdateView):
model = Books
fields = '__all__'
template_name = 'edit-book.html'
def get_success_url(self):
return reverse('bookshelf:bookupdateview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class AuthorAddView(generic.CreateView): class AuthorAddView(generic.CreateView):
model = Author model = Author
...@@ -48,5 +59,15 @@ class AuthorAddView(generic.CreateView): ...@@ -48,5 +59,15 @@ class AuthorAddView(generic.CreateView):
template_name = 'add-author.html' template_name = 'add-author.html'
def get_success(self): def get_success(self):
return reverse('bookshelf:authordetailview', kwarg={'pk': self.object.id}, return reverse('bookshelf:author-detail', kwarg={'pk': self.object.id},
current_app=self.request.resolver_match.namespace) current_app=self.request.resolver_match.namespace)
\ No newline at end of file
class AuthorEditView(generic.UpdateView):
model = Author
fields = '__all__'
template_name = 'edit-author.html'
def get_success_url(self):
return reverse('bookshelf:authorupdateview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
No preview for this file type
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Add Author" <input type="submit" value="Add Author">
</form> </form>
{% endblock content %} {% endblock content %}
\ No newline at end of file
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" value="Add Book" <input type="submit" value="Add Book">
</form> </form>
{% endblock content %} {% endblock content %}
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
{% for Author in object_list %} {% for Author in object_list %}
<li> <li>
<a href="{% url 'author-detail' Author.pk %}"> <a href="/authors/{{Author.pk}}/details">
{{Author.first_name}} {{Author.last_name}} {{Author.first_name}} {{Author.last_name}}
</a> </a>
</li> </li>
......
...@@ -28,5 +28,9 @@ ...@@ -28,5 +28,9 @@
<a href="/books">Books</a> <a href="/books">Books</a>
<a href="/authors">Authors</a> <a href="/authors">Authors</a>
<a href="/home">Home</a> <a href="/home">Home</a>
<br>
<br>
<a href="/authors/{{ object.id }}/edit">
<input type="button" value="Edit Author">
</a>"
{% endblock content %} {% endblock content %}
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<h1>Cheska's Favorite Books</h1> <h1>Cheska's Favorite Books</h1>
{% for Books in object_list %} {% for Books in object_list %}
<li> <li>
<a href="{% url 'books-detail' Books.pk %}"> <a href="/books/{{Books.pk}}/details">
{{Books.title}} {{Books.title}}
</a> </a>
</li> </li>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<a href="/home">Home</a> <a href="/home">Home</a>
<br> <br>
<br> <br>
<a href="/books/"{{ object.id }}/edit/"> <a href="/books/{{object.id}}/edit">
<input type="button" value="Edit Book"> <input type="button" value="Edit Book">
</a>" </a>"
{% endblock content %} {% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<title>Edit Author</title>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block content %}
<title>Edit Author</title>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock content %}
\ 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