Commit 9287decf authored by Angelo Alvarez's avatar Angelo Alvarez

Added Feature: Add Books and Add Authors

parent 75c51014
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Author {% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{ field }}
<span class="spacer"></span>
{% endfor %}
<button type="Submit">Add Author</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Book {% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{% for field in form %}
{{field.label}}: {{ field }}
<span class="spacer"></span>
{% endfor %}
<button type="Submit">Add Book</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -31,6 +31,11 @@ works of classic literature as I progress through my college career.
&nbsp; &nbsp;
<a href="../authors/">Authors</a>
</div>
<div id="links" style="margin: auto; text-align: center; width: 100%">
<a href="../books/add">Add Book</a>
&nbsp; &nbsp;
<a href="../authors/add">Add Author</a>
</div>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import home, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView
from .views import home, BooksListView, BooksDetailView, AuthorListView, AuthorDetailView, BooksCreateView, AuthorCreateView
urlpatterns = [
path('home/', home, name='home'),
#Books
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'),
#Authors
path('authors/', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='authors-details')
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='authors-details'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
]
# This might be needed, depending on your Django version
......
......@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView
from .models import Books, Author
# Create your views here.
......@@ -9,6 +10,8 @@ from .models import Books, Author
def home(request):
return render(request, 'bookshelf/home.html')
##BOOKS
class BooksListView(ListView):
template_name = 'bookshelf/books_list.html'
model = Books
......@@ -17,6 +20,13 @@ class BooksDetailView(DetailView):
template_name = 'bookshelf/books_detail.html'
model = Books
class BooksCreateView(CreateView):
template_name = 'bookshelf/add_book.html'
model = Books
fields = '__all__'
##AUTHORS
class AuthorListView(ListView):
template_name = 'bookshelf/author_list.html'
model = Author
......@@ -26,3 +36,8 @@ class AuthorDetailView(DetailView):
model = Author
booklist = Books.objects.all()
extra_context = { 'books' : booklist }
class AuthorCreateView(CreateView):
template_name = 'bookshelf/add_author.html'
model = Author
fields = '__all__'
\ No newline at end of file
......@@ -37,3 +37,8 @@ ul li {
background: #ddecfc;
margin: 10px;
}
.spacer {
display: block;
margin-bottom: 0.5em;
}
\ 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