Commit 53f031ac authored by Almira Redoble's avatar Almira Redoble

Created views and templates for new books and authors, configured their urls, and updated home.html

parent ba5cebb1
{% extends 'base.html' %}
{% load static %}
{% block title %}
Add New Author
{% endblock %}
{% block heading %}
Add New Author
{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<form action="{{ object.get_absolute_url }}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Add Author">
</form>
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
Add New Book
{% endblock %}
{% block heading %}
Add New Book
{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<form action="{{ object.get_absolute_url }}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
{% block footer %}
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
{% endblock %}
\ No newline at end of file
......@@ -16,4 +16,6 @@
{% block footer %}
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
<a href="{% url 'bookshelf:books-add' %}">Add Book</a>
<a href="{% url 'bookshelf:authors-add' %}">Add Author</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import (
HomePageView, BookListView, BookDetailView,
AuthorListView, AuthorDetailView
HomePageView, BookListView, BookDetailView, AuthorListView,
AuthorDetailView, BookCreateView, AuthorCreateView
)
urlpatterns = [
......@@ -9,7 +9,9 @@ urlpatterns = [
path('books/', BookListView.as_view(), name='books'),
path('authors/', AuthorListView.as_view(), name='authors'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='book-details'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details')
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-details'),
path('books/add', BookCreateView.as_view(), name='books-add'),
path('authors/add', AuthorCreateView.as_view(), name='authors-add'),
]
app_name = "bookshelf"
\ No newline at end of file
......@@ -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, UpdateView
from .models import Books, Author
......@@ -26,6 +27,11 @@ class BookDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
......@@ -33,3 +39,8 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-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