Commit 78a9b85c authored by Jayson Lim's avatar Jayson Lim

Created Edit book and author templates, utilizes the updateview in views file, also configured urls

parent 2a874657
......@@ -7,6 +7,6 @@
<form method="post" style="color: white;">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Create</button>
<button type="submit">Add Author</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -4,9 +4,9 @@
{% block title %}Add New Book{% endblock %}
{% block content %}
<form method="post">
<form method="post" style="color: white;">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Create</button>
<button type="submit">Add Book</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -12,12 +12,26 @@
h1, h2, ul, a, p {
color: white;
}
.button {
display: inline-block;
background-color: #edf3f5;
border: none;
color: black;
padding: 10px 20px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<h1>{{ object }}</h1>
<p style="font-size: 20px">{{ object.age }}</p>
<p style="font-size: 20px">{{ object.nationality }}</p>
<p style="font-size: 20px">{{ object.bio }}</p>
<a href="{% url 'bookshelf:authors-update' object.pk %}" class="button" style="margin-bottom: 20px;">Edit Author</a>
<h2>Books by {{ object }} I love:</h2>
<ul>
{% for book in books %}
......
......@@ -11,6 +11,18 @@
h1, ul, a, p {
color: white;
}
.button {
display: inline-block;
background-color: #edf3f5;
border: none;
color: black;
padding: 10px 20px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<h1>{{ object.title }}</h1>
<a href="{{ author.get_absolute_url }}" style="font-size: 24px">{{ author }}</a>
......@@ -18,6 +30,9 @@
<p style="font-size: 20px">{{ object.year_published }}</p>
<p style="font-size: 20px">{{ object.ISBN }}</p>
<p style="font-size: 20px">{{ object.blurb }}</p>
<a href="{% url 'bookshelf:books-update' object.pk %}" class="button" style="margin-bottom: 20px;">Edit Book</a>
<div style="display: flex; justify-content: space-between;">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form method="post" style="color: white;">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form method="post" style="color: white;">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes</button>
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
from .views import home_view, BooksListView, AuthorsListView, BooksDetailView, AuthorsDetailView, BooksCreateView, AuthorsCreateView
from .views import home_view, BooksListView, AuthorsListView, BooksDetailView
from .views import AuthorsDetailView, BooksCreateView, AuthorsCreateView
from .views import BooksUpdateView, AuthorsUpdateView
urlpatterns = [
path('home/', home_view, name='home'),
......@@ -11,6 +12,8 @@ urlpatterns = [
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
path('books/add/', BooksCreateView.as_view(), name='books-create'),
path('authors/add/', AuthorsCreateView.as_view(), name='authors-create'),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='books-update'),
path('authors/<int:pk>/edit/', AuthorsUpdateView.as_view(), name='authors-update'),
]
app_name = "bookshelf"
......@@ -3,9 +3,9 @@ from django.http import HttpResponse
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import CreateView, UpdateView
from .models import Books, Author
from django.urls import reverse
from django.urls import reverse, reverse_lazy
def home_view(request):
authors_url = reverse('bookshelf:authors')
......@@ -46,10 +46,32 @@ class BooksCreateView(CreateView):
fields = '__all__'
template_name = 'bookshelf/add-book.html'
def get_success_url(self):
return reverse_lazy('bookshelf:books-detail', kwargs={'pk': self.object.pk})
class AuthorsCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
def get_success_url(self):
return reverse_lazy('bookshelf:authors-detail', kwargs={'pk': self.object.pk})
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
def get_success_url(self):
return reverse_lazy('bookshelf:books-detail', kwargs={'pk': self.object.pk})
class AuthorsUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.html'
def get_success_url(self):
return reverse_lazy('bookshelf:authors-detail', kwargs={'pk': self.object.pk})
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