Commit 4548938f authored by justin's avatar justin

feat: added UpdateView for books

parent 2e61b8dd
{% extends 'base.html' %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update" />
</form>
{% endblock %}
...@@ -5,6 +5,7 @@ from .views import ( ...@@ -5,6 +5,7 @@ from .views import (
add_author, add_author,
BookListView, BookListView,
BookDetailView, BookDetailView,
BookUpdateView,
AuthorListView, AuthorListView,
AuthorDetailView, AuthorDetailView,
) )
...@@ -14,6 +15,7 @@ urlpatterns = [ ...@@ -14,6 +15,7 @@ urlpatterns = [
path("books/", BookListView.as_view(), name="book-list"), path("books/", BookListView.as_view(), name="book-list"),
path("books/<int:pk>/details", BookDetailView.as_view(), name="book-detail"), path("books/<int:pk>/details", BookDetailView.as_view(), name="book-detail"),
path("books/add", add_book, name="add-book"), path("books/add", add_book, name="add-book"),
path("books/<int:pk>/edit", BookUpdateView.as_view(), name="update-book"),
path("authors/", AuthorListView.as_view(), name="author-list"), path("authors/", AuthorListView.as_view(), name="author-list"),
path("authors/add", add_author, name="add-author"), path("authors/add", add_author, name="add-author"),
path("authors/<int:pk>/details", AuthorDetailView.as_view(), name="author-detail"), path("authors/<int:pk>/details", AuthorDetailView.as_view(), name="author-detail"),
......
...@@ -2,6 +2,7 @@ from django.shortcuts import render, redirect ...@@ -2,6 +2,7 @@ from django.shortcuts import render, redirect
from django.urls import reverse from django.urls import reverse
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import UpdateView
from .models import Author, Books from .models import Author, Books
from .forms import AuthorForm, BookForm from .forms import AuthorForm, BookForm
...@@ -50,6 +51,12 @@ class BookDetailView(DetailView): ...@@ -50,6 +51,12 @@ class BookDetailView(DetailView):
template_name = "bookshelf/book_details.html" template_name = "bookshelf/book_details.html"
class BookUpdateView(UpdateView):
model = Books
fields = "__all__"
template_name = "bookshelf/edit-book.html"
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
template_name = "bookshelf/authors.html" template_name = "bookshelf/authors.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