Commit 7ecc4213 authored by Elaiza Bolislis's avatar Elaiza Bolislis

Created two new pages that allow the user to edit an existing book and author in the database.

parent ed8c0499
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import (index, homepage,
BooksListView, BooksDetailView, BooksCreateView,
AuthorListView, AuthorDetailView, AuthorCreateView
BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView,
AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView
)
urlpatterns = [
......@@ -11,10 +11,12 @@ urlpatterns = [
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('books/add', BooksCreateView.as_view(), name='books-create'),
path('books/<int:pk>/edit', BooksUpdateView.as_view(), name='books-update'),
path('authors', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details',
AuthorDetailView.as_view(), name='author-detail'),
path('authors/add', AuthorCreateView.as_view(), name='author-create'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name='author-update'),
]
app_name = "bookshelf"
......@@ -26,6 +26,18 @@ class BooksDetailView(DetailView):
template_name = 'bookshelf/book_details.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
......@@ -41,13 +53,13 @@ class AuthorDetailView(DetailView):
return context
class BooksCreateView(CreateView):
model = Books
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-book.html'
template_name = 'bookshelf/add-author.html'
class AuthorCreateView(CreateView):
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
template_name = 'bookshelf/edit-author.html'
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