Commit 2a874657 authored by Jayson Lim's avatar Jayson Lim

Created add book and add author template contains forms that will allow users...

Created add book and add author template contains forms that will allow users to add new books and authors
parent cf160dad
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form method="post" style="color: white;">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Create</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 %}
{{ form.as_p }}
<button type="submit">Create</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %} {% extends 'base.html' %}
{% load static %} {% load static %}
{% block title %}My Favourite Authors{% endblock %} {% block title %}Add New Author{% endblock %}
{% block content %} {% block content %}
<style> <style>
......
from django.urls import path from django.urls import path
from . import views from . import views
from .views import home_view, BooksListView, AuthorsListView, BooksDetailView, AuthorsDetailView from .views import home_view, BooksListView, AuthorsListView, BooksDetailView, AuthorsDetailView, BooksCreateView, AuthorsCreateView
urlpatterns = [ urlpatterns = [
...@@ -9,6 +9,8 @@ urlpatterns = [ ...@@ -9,6 +9,8 @@ urlpatterns = [
path('authors/', AuthorsListView.as_view(), name='authors'), path('authors/', AuthorsListView.as_view(), name='authors'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'), path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'), path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
path('books/add/', BooksCreateView.as_view(), name='books-create'),
path('authors/add/', AuthorsCreateView.as_view(), name='authors-create'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
...@@ -3,6 +3,7 @@ from django.http import HttpResponse ...@@ -3,6 +3,7 @@ from django.http import HttpResponse
from django.views import View from django.views import View
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
from django.views.generic.edit import CreateView
from .models import Books, Author from .models import Books, Author
from django.urls import reverse from django.urls import reverse
...@@ -40,5 +41,15 @@ class AuthorsDetailView(DetailView): ...@@ -40,5 +41,15 @@ class AuthorsDetailView(DetailView):
context['books'] = Books.objects.filter(author=author) context['books'] = Books.objects.filter(author=author)
return context return context
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorsCreateView(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