Add UpdateViews for updating authors and books

parent 19ac7735
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Author {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<br>
<input type="submit" value="Save Changes">
</form>
<br><hr>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Book {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<br>
<input type="submit" value="Save Changes">
</form>
<br><hr>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, AuthorCreateView, BooksCreateView
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, AuthorCreateView, BooksCreateView, AuthorUpdateView, BooksUpdateView
urlpatterns = [
path('', HomeView, name='index'),
......@@ -7,8 +7,11 @@ urlpatterns = [
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('authors/add', AuthorCreateView.as_view(), name='author-add'),
path('books/add', BooksCreateView.as_view(), name='book-add'),
path('books/add', BooksCreateView.as_view(), name='books-add'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name='author-edit'),
path('books/<int:pk>/edit', BooksUpdateView.as_view(), name='books-edit'),
]
# This might be needed, depending on your Django version
......
......@@ -31,3 +31,13 @@ class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = ["first_name", "last_name", "age", "nationality", "bio"]
template_name = 'bookshelf/edit-author.html'
class BooksUpdateView(UpdateView):
model = Books
fields = ["title", "author", "publisher", "year_published", "ISBN", "blurb"]
template_name = 'bookshelf/edit-book.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