Commit ed8c0499 authored by Elaiza Bolislis's avatar Elaiza Bolislis

Created two new pages that allow users to add new books and new authors into the database.

parent 7cfaff4c
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Author">
</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 %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import (index, homepage,
BooksListView, BooksDetailView,
AuthorListView, AuthorDetailView
BooksListView, BooksDetailView, BooksCreateView,
AuthorListView, AuthorDetailView, AuthorCreateView
)
urlpatterns = [
......@@ -10,9 +10,11 @@ urlpatterns = [
path('home', homepage, name='home'),
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('books/add', BooksCreateView.as_view(), name='books-create'),
path('authors', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details',
AuthorDetailView.as_view(), name='author-detail'),
path('authors/add', AuthorCreateView.as_view(), name='author-create'),
]
app_name = "bookshelf"
from django.shortcuts import render
from django.shortcuts import render, redirect
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, UpdateView
from .models import Author, Books
......@@ -38,3 +39,15 @@ class AuthorDetailView(DetailView):
context = super().get_context_data(**kwargs)
context['books'] = Books.objects.all()
return context
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
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