Commit e9e9be93 authored by Gabriel Geraldo's avatar Gabriel Geraldo

implemented add and edit Author features

parent 6b9af395
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Author {% endblock %}
{% block style %}
<link rel='stylesheet' type='text/css' href="{% static 'base.css' %}"/>
{% endblock %}
{% block content %}
<header>Add New Author</header>
<section>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Author">
</form>
</section>
{% endblock %}
\ No newline at end of file
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
<li class="subinfo">Age: {{ object.age }}</li> <li class="subinfo">Age: {{ object.age }}</li>
<li class="subinfo">Nationality: {{ object.nationality }}</li> <li class="subinfo">Nationality: {{ object.nationality }}</li>
<li class="subinfo">Bio:<br>{{ object.bio}}</li> <li class="subinfo">Bio:<br>{{ object.bio}}</li>
<form action="edit">
<input type="submit" value="Edit Author" />
</form>
</ul> </ul>
</section> </section>
<section> <section>
......
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Author {% endblock %}
{% block style %}
<link rel='stylesheet' type='text/css' href="{% static 'base.css' %}"/>
{% endblock %}
{% block content %}
<header>Edit Author</header>
<section>
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
</section>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index_view, home_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView from .views import index_view, home_view, BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView, AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView
urlpatterns = [ urlpatterns = [
...@@ -11,6 +11,8 @@ urlpatterns = [ ...@@ -11,6 +11,8 @@ urlpatterns = [
path('books/<int:pk>/edit', BooksUpdateView.as_view(), name="books_edit"), path('books/<int:pk>/edit', BooksUpdateView.as_view(), name="books_edit"),
path('authors/', AuthorListView.as_view(template_name='bookshelf/authors.html'), name='authors'), path('authors/', AuthorListView.as_view(template_name='bookshelf/authors.html'), name='authors'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(template_name='bookshelf/author_details.html'), name='author_details'), path('authors/<int:pk>/details', AuthorDetailView.as_view(template_name='bookshelf/author_details.html'), name='author_details'),
path('authors/add', AuthorCreateView.as_view(), name='author_add'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name="author_edit"),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -34,7 +34,6 @@ class BooksUpdateView(UpdateView): ...@@ -34,7 +34,6 @@ class BooksUpdateView(UpdateView):
fields = "__all__" fields = "__all__"
template_name = "bookshelf/edit-book.html" template_name = "bookshelf/edit-book.html"
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
...@@ -45,3 +44,13 @@ class AuthorListView(ListView): ...@@ -45,3 +44,13 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
class AuthorCreateView(CreateView):
model = Author
fields = "__all__"
template_name = "bookshelf/add-author.html"
class AuthorUpdateView(UpdateView):
model = Author
fields = "__all__"
template_name = "bookshelf/edit-author.html"
\ No newline at end of file
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