Commit 139b0a03 authored by Sharmaine Chua's avatar Sharmaine Chua

added form pages and edited the template file

parent 46b8410e
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<div class="add-author">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<div class="add_book">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
<a href="../authors"> <a href="../authors">
<button type="button"><p>Authors</p></button> <button type="button"><p>Authors</p></button>
</a> </a>
<br>
<a href="../books/add">Add Book</a>
<a href="../authors/add">Add Author</a>
</div> </div>
</center> </center>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -7,6 +7,8 @@ urlpatterns = [ ...@@ -7,6 +7,8 @@ urlpatterns = [
path('books/<int:pk>/details',BooksDetailView.as_view(),name='book_details'), path('books/<int:pk>/details',BooksDetailView.as_view(),name='book_details'),
path('authors/',AuthorListView.as_view(),name='author_list'), path('authors/',AuthorListView.as_view(),name='author_list'),
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',BooksCreateView.as_view(),name='create_book'),
path('authors/add',AuthorCreateView.as_view(),name='new_author'),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
...@@ -2,6 +2,7 @@ from django.shortcuts import render ...@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.http import HttpResponse, request from django.http import HttpResponse, request
from django.views import View from django.views import View
from .models import Author, Books from .models import Author, Books
from django.views.generic.edit import CreateView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
...@@ -17,6 +18,11 @@ class BooksDetailView(DetailView): ...@@ -17,6 +18,11 @@ class BooksDetailView(DetailView):
model = Books model = Books
template_name='bookshelf/book_details.html' template_name='bookshelf/book_details.html'
class BooksCreateView(CreateView):
model = Books
template_name = 'bookshelf/add-book.html'
fields = '__all__'
class AuthorListView(ListView): class AuthorListView(ListView):
model = Author model = Author
template_name='bookshelf/authors.html' template_name='bookshelf/authors.html'
...@@ -24,3 +30,8 @@ class AuthorListView(ListView): ...@@ -24,3 +30,8 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
template_name='bookshelf/author_details.html' template_name='bookshelf/author_details.html'
class AuthorCreateView(CreateView):
model = Author
template_name = 'bookshelf/add-author.html'
fields = '__all__'
\ 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