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 @@ ...@@ -12,6 +12,10 @@
<p>Bio: {{object.bio}}</p> <p>Bio: {{object.bio}}</p>
</div> </div>
<a href="../edit/">
<input type="submit" value="Edit Author">
</a>
<div> <div>
<p>Books by {{object}} that I love:</p> <p>Books by {{object}} that I love:</p>
{% for book in object.books.all %} {% 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 = [ ...@@ -9,6 +9,7 @@ urlpatterns = [
path('authors/<int:pk>/details/', AuthorView.as_view(), name = 'authors_details'), path('authors/<int:pk>/details/', AuthorView.as_view(), name = 'authors_details'),
path('books/<int:pk>/details/', BookView.as_view(), name = 'books_details'), path('books/<int:pk>/details/', BookView.as_view(), name = 'books_details'),
path('authors/add/', AuthorCreateView.as_view(), name = 'add-author'), 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/add/', BooksCreateView.as_view(), name = 'add-book'),
path('books/<int:pk>/edit/', BooksCreateView.as_view(), name = 'edit-book') path('books/<int:pk>/edit/', BooksCreateView.as_view(), name = 'edit-book')
] ]
......
...@@ -44,6 +44,13 @@ class AuthorCreateView(CreateView): ...@@ -44,6 +44,13 @@ class AuthorCreateView(CreateView):
else: else:
return render(request, self.template_name, {'form': form}) 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): class BooksCreateView(CreateView):
model = Books model = Books
form = BookForm # Can be removed? form = BookForm # Can be removed?
......
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