Commit 452e883d authored by Joei Yucoco's avatar Joei Yucoco

Added working buttons to edit Books and Authors

- Added links to homepage to add books and authors
- UpdateView was used
parent 5410d2b1
......@@ -6,6 +6,15 @@
<h3>{{object.age}}</h3>
<h3>{{object.nationality}}</h3>
<h3>{{object.bio}}</h3>
<br>
<h3>
<button>
<a href="{% url 'bookshelf:authors-edit' object.id %}">
Edit Author
</a>
</button>
<br>
</h3>
<h2> Books by {{object}} I love:</h2>
<ul>
......
......@@ -15,6 +15,13 @@
<br>
<h3>
<button>
<a href="{% url 'bookshelf:books-edit' object.id %}">
Edit Book
</a>
</button>
<br>
<a href="{{ object.get_absolute_home_url }}" >
Home
</a>
......
<!DOCTYPE html>
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
<!DOCTYPE html>
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
......@@ -17,6 +17,14 @@
<a href="{{ author.get_absolute_AuthorsList_url }}" >
Authors
</a>
<br>
<a href="{% url 'bookshelf:books-add' %}" >
Add Book
</a>
&nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:authors-add' %}" >
Add Author
</a>
</h3>
......
from django.urls import path
from .views import (HomeView, BooksView, BookDetailsView,
AuthorsView, AuthorDetailsView, AuthorAddView, BookAddView)
from .views import (HomeView, BooksView, BookDetailsView, AuthorsView,
AuthorDetailsView, AuthorAddView, BookAddView, AuthorEditView,
BookEditView)
urlpatterns = [
path('home/', HomeView, name='home'),
......@@ -10,6 +11,8 @@ urlpatterns = [
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name='authors-detail'),
path('authors/add/', AuthorAddView.as_view(), name='authors-add'),
path('books/add/', BookAddView.as_view(), name='books-add'),
path('authors/<int:pk>/edit/', AuthorEditView.as_view(), name='authors-edit'),
path('books/<int:pk>/edit/', BookEditView.as_view(), name='books-edit'),
]
app_name = "bookshelf"
......@@ -4,7 +4,7 @@ from django.views import View
from django.urls import reverse
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import CreateView, UpdateView
from .forms import AuthorForm, BooksForm
from .models import Author, Books
......@@ -37,7 +37,7 @@ class AuthorDetailsView(DetailView):
class AuthorAddView(CreateView):
model = Author
form_class = AuthorForm
template_name = 'bookshelf/author_add.html'
template_name = 'bookshelf/add-author.html'
def get_success_url(self):
return reverse('bookshelf:authors-detail', kwargs={'pk': self.object.pk})
......@@ -46,7 +46,25 @@ class AuthorAddView(CreateView):
class BookAddView(CreateView):
model = Books
form_class = BooksForm
template_name = 'bookshelf/book_add.html'
template_name = 'bookshelf/add-book.html'
def get_success_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.object.pk})
class AuthorEditView(UpdateView):
model = Author
form_class = AuthorForm
template_name = 'bookshelf/edit-author.html'
def get_success_url(self):
return reverse('bookshelf:authors-detail', kwargs={'pk': self.object.pk})
class BookEditView(UpdateView):
model = Books
form_class = BooksForm
template_name = 'bookshelf/edit-book.html'
def get_success_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.object.pk})
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