Commit 54e0caad authored by RJC's avatar RJC

added authorcreateview to views.py in bookshelf module

parent 069233c1
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block header %}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
from django.shortcuts import render from django.shortcuts import render
from django.views import generic from django.views import generic
from django.urls import reverse
from .models import Books, Author from .models import Books, Author
# Create your views here. # Create your views here.
...@@ -21,6 +22,10 @@ class BookCreateView(generic.CreateView): ...@@ -21,6 +22,10 @@ class BookCreateView(generic.CreateView):
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
def get_success_url(self):
return reverse('bookshelf:bookdetailview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class BookDetailView(generic.DetailView): class BookDetailView(generic.DetailView):
model = Books model = Books
...@@ -36,6 +41,16 @@ class AuthorListView(generic.ListView): ...@@ -36,6 +41,16 @@ class AuthorListView(generic.ListView):
context_object_name = 'authors' context_object_name = 'authors'
class AuthorCreateView(generic.CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
def get_success_url(self):
return reverse('bookshelf:authordetailview', kwargs={'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
class AuthorDetailView(generic.DetailView): class AuthorDetailView(generic.DetailView):
model = Author model = Author
template_name = 'bookshelf/author_detail.html' template_name = 'bookshelf/author_detail.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