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
from . import views
from .views import (HomeView, BooksListView, BooksDetailView,
AuthorListView, AuthorDetailView, BookAddView,
AuthorAddView)
AuthorAddView, AuthorEditView, BookEditView)
urlpatterns = [
......@@ -14,9 +14,12 @@ urlpatterns = [
path('authors/', AuthorListView.as_view(), name='author'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(),
name='author-detail'),
path('books/add', BookAddView.as_view(), name='author'),
path('authors/add', AuthorAddView.as_view(), name='author'),
path('books/add', BookAddView.as_view(), name='bookdetailview'),
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'
......@@ -3,6 +3,7 @@ from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views import generic
from .models import Books
from django.urls import reverse
from .models import Author
......@@ -38,7 +39,17 @@ class BookAddView(generic.CreateView):
template_name = 'add-book.html'
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)
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)
......@@ -48,5 +59,15 @@ class AuthorAddView(generic.CreateView):
template_name = 'add-author.html'
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)
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 @@
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Author"
<input type="submit" value="Add Author">
</form>
{% endblock content %}
\ No newline at end of file
......@@ -8,6 +8,6 @@
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book"
<input type="submit" value="Add Book">
</form>
{% endblock content %}
\ No newline at end of file
......@@ -8,7 +8,7 @@
{% for Author in object_list %}
<li>
<a href="{% url 'author-detail' Author.pk %}">
<a href="/authors/{{Author.pk}}/details">
{{Author.first_name}} {{Author.last_name}}
</a>
</li>
......
......@@ -28,5 +28,9 @@
<a href="/books">Books</a>
<a href="/authors">Authors</a>
<a href="/home">Home</a>
<br>
<br>
<a href="/authors/{{ object.id }}/edit">
<input type="button" value="Edit Author">
</a>"
{% endblock content %}
\ No newline at end of file
......@@ -5,7 +5,7 @@
<h1>Cheska's Favorite Books</h1>
{% for Books in object_list %}
<li>
<a href="{% url 'books-detail' Books.pk %}">
<a href="/books/{{Books.pk}}/details">
{{Books.title}}
</a>
</li>
......
......@@ -16,7 +16,7 @@
<a href="/home">Home</a>
<br>
<br>
<a href="/books/"{{ object.id }}/edit/">
<a href="/books/{{object.id}}/edit">
<input type="button" value="Edit Book">
</a>"
{% 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