Commit fa5ac0e4 authored by Jan Ericsson Ong Ang's avatar Jan Ericsson Ong Ang

edited the 4 new html files for the forms to work

parent a0de761a
......@@ -7,15 +7,15 @@
<form method="post">
{% csrf_token %}
<label>First Name: </label>
<input id="first_name" type="text" name="first_name" max length="50"/>
<input id="first_name" type="text" name="first_name" max length="50"/><br>
<label>Last Name: </label>
<input id="last_name" type="text" name="last_name" max length="100"/>
<input id="last_name" type="text" name="last_name" max length="100"/><br>
<label>Age: </label>
<input id="age" type="number" name="age"/>
<input id="age" type="number" name="age"/><br>
<label>Nationality: </label>
<input id="nationality" type="text" name="nationality"/>
<input id="nationality" type="text" name="nationality"/><br>
<label>Bio: </label>
<input id="bio" type="text" name="bio"/>
<input id="bio" type="text" name="bio"/><br>
</form>
<button type="button">
......
......@@ -7,17 +7,17 @@
<form method="post">
{% csrf_token %}
<label>Title: </label>
<input id="title" type="text" name="title" max length="50"/>
<input id="title" type="text" name="title" max length="50"/><br>
<label>Author: </label>
<input id="author" type="text" name="author" max length="100"/>
<input id="author" type="text" name="author" max length="100"/><br>
<label>Publisher: </label>
<input id="publisher" type="text" name="publisher"/>
<input id="publisher" type="text" name="publisher"/><br>
<label>Year Published: </label>
<input id="year_published" type="number" name="year_published"/>
<input id="year_published" type="number" name="year_published"/><br>
<label>ISBN: </label>
<input id="ISBN" type="number" name="ISBN"/>
<input id="ISBN" type="number" name="ISBN"/><br>
<label>Blurb: </label>
<input id="blurb" type="text" name="blurb"/>
<input id="blurb" type="text" name="blurb"/><br>
</form>
<button type="button">
......
......@@ -10,15 +10,15 @@
<p>{{ author.bio }}</p>
<button type="button">
<a href="/bookshelf/books/{{ book.id }}/edit/">
Edit Book
<a href="/bookshelf/authors/{{ author.id }}/edit/">
Edit Author
</a>
</button><br>
<p>Books by {{ author.first_name }} {{ author.last_name }} I love</p>
{% for authbook in author.books_set.all %}
<a href="/bookshelf/authors/{{ authbook.id }}/details/">{{ authbook }}<br></a>
<a href="/bookshelf/books/{{ authbook.id }}/details/">{{ authbook }}<br></a>
{% endfor %}
<br>
......
......@@ -7,15 +7,15 @@
<form method="post">
{% csrf_token %}
<label>First Name: </label>
<input id="first_name" type="text" name="first_name" max length="50"/>
<input id="first_name" type="text" name="first_name" max length="50"/><br>
<label>Last Name: </label>
<input id="last_name" type="text" name="last_name" max length="100"/>
<input id="last_name" type="text" name="last_name" max length="100"/><br>
<label>Age: </label>
<input id="age" type="number" name="age"/>
<input id="age" type="number" name="age"/><br>
<label>Nationality: </label>
<input id="nationality" type="text" name="nationality"/>
<input id="nationality" type="text" name="nationality"/><br>
<label>Bio: </label>
<input id="bio" type="text" name="bio"/>
<input id="bio" type="text" name="bio"/><br>
</form>
<button type="button">
......
......@@ -7,17 +7,17 @@
<form method="post">
{% csrf_token %}
<label>Title: </label>
<input id="title" type="text" name="title" max length="50"/>
<input id="title" type="text" name="title" max length="50"/><br>
<label>Author: </label>
<input id="author" type="text" name="author" max length="100"/>
<input id="author" type="text" name="author" max length="100"/><br>
<label>Publisher: </label>
<input id="publisher" type="text" name="publisher"/>
<input id="publisher" type="text" name="publisher"/><br>
<label>Year Published: </label>
<input id="year_published" type="number" name="year_published"/>
<input id="year_published" type="number" name="year_published"/><br>
<label>ISBN: </label>
<input id="ISBN" type="number" name="ISBN"/>
<input id="ISBN" type="number" name="ISBN"/><br>
<label>Blurb: </label>
<input id="blurb" type="text" name="blurb"/>
<input id="blurb" type="text" name="blurb"/><br>
</form>
<button type="button">
......
from django.urls import path
from . import views
from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetailView
from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetailView, AuthorCreateView, AuthorUpdateView, BooksCreateView, BooksUpdateView
# url for bookshelf
......@@ -8,12 +8,12 @@ urlpatterns = [
path('', views.HomeView, name='home'),
path('authors/', AuthorView.as_view(), name='authors'),
path('authors/<int:id>/details/', AuthorDetailView.as_view(), name='author-detail'),
path('authors/<int:id>/add/', AuthorDetailView.as_view(), name='add-author'),
path('authors/<int:id>/edit/', AuthorDetailView.as_view(), name='edit-author'),
path('authors/<int:id>/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:id>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
path('books/', BooksView.as_view(), name='books'),
path('books/<int:id>/details/', BookDetailView.as_view(), name='books-detail'),
path('books/<int:id>/add/', BookDetailView.as_view(), name='add-book'),
path('books/<int:id>/edit/', BookDetailView.as_view(), name='edit-book'),
path('books/<int:id>/add/', BooksCreateView.as_view(), name='add-book'),
path('books/<int:id>/edit/', BooksUpdateView.as_view(), name='edit-book'),
]
app_name = 'bookshelf'
\ No newline at end of file
......@@ -2,8 +2,9 @@ from django.shortcuts import render
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
from.forms import AuthorForm, BookForm
from .forms import AuthorForm, BookForm
# Create your views here.
......@@ -12,23 +13,26 @@ def HomeView(request):
return render(request, 'bookshelf/home.html', {'nickname': 'Jan'})
#CBV
#Author
class AuthorView(ListView):
pk_url_kwarg = 'id'
model = Author
queryset = Author.objects.all()
def get(self, request):
author_data = Author.objects.all().values()
return render(request, 'bookshelf/authors.html', {'nickname': 'Jan', 'author_data': author_data})
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form']= AuthorForm()
return context
def post(self, request, *args, **kwargs):
form = AuthorForm(request.POST)
if form.is_valid():
return self.get(request, *args, **kwargs)
else:
return render(request, 'bookshelf/author_details.html', {'form': form})
class AuthorCreateView(CreateView):
pk_url_kwarg = 'id'
model = Author
fields = "__all__"
template_name = 'bookshelf/add-author.html'
class AuthorUpdateView(UpdateView):
pk_url_kwarg = 'id'
model = Author
fields = "__all__"
template_name = 'bookshelf/edit-author.html'
class AuthorDetailView(DetailView):
pk_url_kwarg = 'id'
......@@ -37,22 +41,26 @@ class AuthorDetailView(DetailView):
template_name = 'bookshelf/author_details.html'
context_object_name = 'author'
#Books
class BooksView(ListView):
pk_url_kwarg = 'id'
model = Books
queryset = Books.objects.all()
def get(self, request):
book_data = Books.objects.all().values()
return render(request, 'bookshelf/books.html', {'nickname': 'Jan', 'book_data': book_data})
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form']= BookForm()
return context
def post(self, request, *args, **kwargs):
form = BookForm(request.POST)
if form.is_valid():
return self.get(request, *args, **kwargs)
else:
return render(request, 'bookshelf/book_details.html', {'form': form})
class BooksCreateView(CreateView):
pk_url_kwarg = 'id'
model = Books
fields = "__all__"
template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
pk_url_kwarg = 'id'
model = Books
fields = "__all__"
template_name = 'bookshelf/edit-book.html'
class BookDetailView(DetailView):
pk_url_kwarg = 'id'
......
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