Add CreateView for adding Books

parent b338ab23
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Book {% endblock %}
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<br>
<input type="submit" value="Add Book">
</form>
<br><hr>
{% endblock %}
\ No newline at end of file
......@@ -8,5 +8,6 @@
<p> Hi! My name is Joaqs! I usually like science fiction books and non-fiction books, but my favorite book series is A Song of Ice and Fire by George R. R. Martin. </p>
<p> While I don't have a favorite author, I usually enjoy books that are experimental or have good twists. &#9786; </p>
<br><hr><br><br>
<a href="../authors/">Authors</a> &nbsp; <a href="../books/">Books</a>
<a href="../authors/">Authors</a> &nbsp; <a href="../books/">Books</a><br>
<a href="../authors/add">Add Author</a> &nbsp; <a href="../books/add">Add Book</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, AuthorCreateView
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, AuthorCreateView, BooksCreateView
urlpatterns = [
path('', HomeView, name='index'),
......@@ -8,6 +8,7 @@ urlpatterns = [
path('books', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('authors/add', AuthorCreateView.as_view(), name='author-add'),
path('books/add', BooksCreateView.as_view(), name='book-add'),
]
# This might be needed, depending on your Django version
......
......@@ -26,3 +26,8 @@ class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.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