Add CreateView for adding Authors

parent 0d3709e9
{% extends 'base.html' %}
{% load static %}
{% block title %} Add New Author {% 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 Author">
</form>
<br><hr>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView
from .views import HomeView, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, AuthorCreateView
urlpatterns = [
path('', HomeView, name='index'),
......@@ -7,6 +7,7 @@ urlpatterns = [
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
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'),
]
# This might be needed, depending on your Django version
......
......@@ -3,6 +3,7 @@ from django.http import HttpResponse
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 Author, Books
......@@ -20,3 +21,8 @@ class BooksListView(ListView):
class BooksDetailView(DetailView):
model = Books
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