Commit b01f17f2 authored by Colleen's avatar Colleen

Updated the edit templates, views and urls

parent 753b82be
{% 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 action="/add_author" method="post">
{% csrf_token %}
{{ form }}
First Name: <input type="text" name="title"/><br>
Last Name: <input type="text" name="author"/><br>
Age: <input type="text" name="publisher"/><br>
Nationality: <input type="text" name="year_published"/><br>
Bio: <input type="text" name="ISBN"/><p>
<input type="submit" value="Save Changes"/>
</form>
{% endblock %}
\ No newline at end of file
{% 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 action="/add_book" method="post">
{% csrf_token %}
{{ form }}
Title: <input type="text" name="title"/><br>
Author: <input type="text" name="author"/><br>
Publisher: <input type="text" name="publisher"/><br>
Year Published: <input type="text" name="year_published"/><br>
ISBN: <input type="text" name="ISBN"/><br>
Blurb: <input type="text" name="blurb"/><br>
<input type="submit" value="Save Changes"/>
</form>
{% endblock %}
\ No newline at end of file
...@@ -12,10 +12,22 @@ ...@@ -12,10 +12,22 @@
</a> </a>
</li> </li>
</ul> </ul>
<ul>
<li>
<a href="/bookshelf/books/add"> add books
</a>
</li>
</ul>
<ul> <ul>
<li> <li>
<a href="/bookshelf/authors"> authors <a href="/bookshelf/authors"> authors
</a> </a>
</li> </li>
</ul> </ul>
<ul>
<li>
<a href="/bookshelf/author/add"> add authors
</a>
</li>
</ul>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import HomepageView,BooksListView,BooksDetailView,AuthorListView,AuthorDetailView from .views import HomepageView,BooksListView,BooksDetailView,AuthorListView,AuthorDetailView,AuthorUpdateView,Book_view,Author_view
urlpatterns = [ urlpatterns = [
path('', HomepageView, name='homeview'), path('', HomepageView, name='homeview'),
path('books', BooksListView.as_view(), name='books-list'), path('books', BooksListView.as_view(), name='books-list'),
path('books/add/', Book_view, name='books-add'),
path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'), path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'),
path('authors', AuthorListView.as_view(), name='authors-list'), path('author', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>', AuthorDetailView.as_view(), name='authors-detail'), path('author/<int:pk>', AuthorDetailView.as_view(), name='author-detail'),
path('author/add', Author_view, name='author-add'),
path('author/<int:pk>', AuthorUpdateView.as_view(), name='author-update'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from django.views import View from django.views import View
from django.shortcuts import render, redirect
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from django.shortcuts import render from django.shortcuts import render
from .models import Author, Books from .models import Author, Books
from .forms import BooksForm, AuthorForm
def HomepageView(request): def HomepageView(request):
return render(request, 'bookshelf/home.html', {'name':'Ian'}) return render(request, 'bookshelf/home.html', {'name':'Colleen'})
def Book_view(request):
if request.method == 'POST':
form = BooksForm(request.POST)
if form.is_valid():
new_subject = form.save()
return redirect('book_detail', pk=new_subject.pk)
else:
form = BooksForm()
return render(request, 'bookshelf/add-book.html', {'form': form})
def Author_view(request):
if request.method == 'POST':
form = AuthorForm(request.POST)
if form.is_valid():
new_subject = form.save()
return redirect('author_detail', pk=new_subject.pk)
else:
form = AuthorForm()
return render(request, 'bookshelf/add-author.html', {'form': form})
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
...@@ -20,3 +43,23 @@ class AuthorListView(ListView): ...@@ -20,3 +43,23 @@ class AuthorListView(ListView):
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'edit-book.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'add-author.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'edit-author.html'
No preview for this file type
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