Commit 06f368a5 authored by Washington99's avatar Washington99

Implemented the button for edit

The button was made to redirect to the link that was asked in the specs. The save changes button is still non-working.
parent 76997972
......@@ -16,7 +16,7 @@
</ul>
{% endif %}
{% endfor %}
<form act method="post">
<form method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Add Book">
......
......@@ -19,7 +19,14 @@
<p>{{object.blurb}}</p>
</div>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
<a href="../edit/">
<input type="submit" value="Edit Book">
</a>
<div>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
</div>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Book</title>
</head>
<body>
{{ 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 }}
<input type="submit" value="Save Changes">
</form>
</body>
</html>
\ No newline at end of file
......@@ -9,6 +9,7 @@ urlpatterns = [
path('authors/<int:pk>/details/', AuthorView.as_view(), name = 'authors_details'),
path('books/<int:pk>/details/', BookView.as_view(), name = 'books_details'),
path('books/add/', BooksCreateView.as_view(), name = 'add-book'),
path('books/<int:pk>/edit/', BooksCreateView.as_view(), name = 'edit-book')
]
app_name = "bookshelf"
......
......@@ -35,7 +35,6 @@ class BooksCreateView(CreateView):
template_name = 'bookshelf/add-book.html'
def post(self, request, *args, **kwargs):
form = BookForm(request.POST) # Create a Form object from the POST values
if form.is_valid():
new_book = form.save()
......@@ -44,4 +43,10 @@ class BooksCreateView(CreateView):
# return self.get(request, *args, **kwargs)
else:
return render(request, self.template_name, {'form': form})
class BooksCreateView(UpdateView):
model = Books
fields = '__all__'
# template to be used by default is called <model>_form.html
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