Commit dd53c2dd authored by Jose Enrique D. Siongco's avatar Jose Enrique D. Siongco

Merge branch 'lab04' into 'master'

Lab04

See merge request !1
parents 20458dc8 18ba017f
from django.urls import path
from .views import (
BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView, HomepageView
BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView,
HomepageView, AuthorCreateView, BooksCreateView, BooksUpdateView,
AuthorUpdateView
)
urlpatterns = [
......@@ -10,4 +12,8 @@ urlpatterns = [
path('authors/', AuthorsListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
path('home/', HomepageView, name='home'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('books/add/', BooksCreateView.as_view(), name='add-author'),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='edit-book'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
]
......@@ -3,6 +3,7 @@ from django.shortcuts import render
from django.template import loader
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books
......@@ -29,6 +30,28 @@ class AuthorsDetailView(DetailView):
model = Author
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'add-author.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = "edit-book.html"
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = "edit-author.html"
'''
books = Books.objects.filter(author=Author)
extra_context = {'books': books.author.all()}
......
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
\ No newline at end of file
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
\ No newline at end of file
......@@ -6,6 +6,8 @@
{% block content %}
{% block body %}
{% endblock %}
<button type = "button"
onclick="window.location.href='../edit/'">Edit Author</button>
<a href="/home/">Home</a>
<a href="/books/">Books</a>
<a href="/authors/">Authors</a>
......
......@@ -24,6 +24,14 @@
a:active{
color: #3c6b64;
}
button{
padding: 10px;
text-decoration: none;
border-radius: 25px;
background-color: #c1e3ed;
font-family: Century Gothic;
text-decoration: none;
}
</style>
</head>
......
......@@ -7,7 +7,8 @@
{% block body %}
{% endblock %}
<button type = "button"
onclick="window.location.href='../edit/'">Edit Book</button>
<a href="/home/">Home</a>
<a href="/books/">Books</a>
<a href="/authors/">Authors</a>
......
......@@ -13,4 +13,7 @@ My Favourite Books and Authors
</p>
<a href="/books/">Books</a>
<a href="/authors/">Authors</a>
<br>
<a href="/books/add">Add Book</a>
<a href="/authors/add">Add Author</a>
{% endblock %}
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
\ No newline at end of file
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
\ 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