Commit e7cd1f8f authored by Washington99's avatar Washington99

Implemented functioning edit author method

The details page of every database entry of author model now has an edit author button. The button successfully updates the entry values and redirects to the details page afterwards.
parent 19ff60ac
......@@ -12,6 +12,10 @@
<p>Bio: {{object.bio}}</p>
</div>
<a href="../edit/">
<input type="submit" value="Edit Author">
</a>
<div>
<p>Books by {{object}} that I love:</p>
{% for book in object.books.all %}
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Author</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('authors/add/', AuthorCreateView.as_view(), name = 'add-author'),
path('authors/<int:pk>/edit/', AuthorCreateView.as_view(), name = 'edit-author'),
path('books/add/', BooksCreateView.as_view(), name = 'add-book'),
path('books/<int:pk>/edit/', BooksCreateView.as_view(), name = 'edit-book')
]
......
......@@ -43,6 +43,13 @@ class AuthorCreateView(CreateView):
# return self.get(request, *args, **kwargs)
else:
return render(request, self.template_name, {'form': form})
class AuthorCreateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.html'
success_url = "../details/"
class BooksCreateView(CreateView):
model = Books
......
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