Commit 2a66faa4 authored by Jan Ericsson Ong Ang's avatar Jan Ericsson Ong Ang

edited all 4 forms htmls

parent dfc01886
<form>
<label>First Name: </label>
<input id="first_name" type="text" name="first_name" max length="50" required/>
<label>Last Name: </label>
<input id="last_name" type="text" name="last_name" max length="100" required/>
<label>Age: </label>
<input id="age" type="number" name="age" required/>
<label>Nationality: </label>
<input id="nationality" type="text" name="nationality" required/>
<label>Bio: </label>
<input id="bio" type="text" name="bio" required/>
</form>
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form>
<label>First Name: </label>
<input id="first_name" type="text" name="first_name" max length="50" required/>
<label>Last Name: </label>
<input id="last_name" type="text" name="last_name" max length="100" required/>
<label>Age: </label>
<input id="age" type="number" name="age" required/>
<label>Nationality: </label>
<input id="nationality" type="text" name="nationality" required/>
<label>Bio: </label>
<input id="bio" type="text" name="bio" required/>
</form>
<button type="button">
<a href="/bookshelf/authors/{{ author.id }}/details/">
Add Author
</a>
</button><br>
{% endblock %}
\ No newline at end of file
<form>
<label>Title: </label>
<input id="title" type="text" name="title" max length="50" required/>
<label>Author: </label>
<input id="author" type="text" name="author" max length="100" required/>
<label>Publisher: </label>
<input id="publisher" type="text" name="publisher" required/>
<label>Year Published: </label>
<input id="year_published" type="number" name="year_published" required/>
<label>ISBN: </label>
<input id="ISBN" type="number" name="ISBN" required/>
<label>Blurb: </label>
<input id="blurb" type="text" name="blurb" required/>
</form>
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form>
<label>Title: </label>
<input id="title" type="text" name="title" max length="50" required/>
<label>Author: </label>
<input id="author" type="text" name="author" max length="100" required/>
<label>Publisher: </label>
<input id="publisher" type="text" name="publisher" required/>
<label>Year Published: </label>
<input id="year_published" type="number" name="year_published" required/>
<label>ISBN: </label>
<input id="ISBN" type="number" name="ISBN" required/>
<label>Blurb: </label>
<input id="blurb" type="text" name="blurb" required/>
</form>
<button type="button">
<a href="/bookshelf/books/{{ book.id }}/details/">
Add Book
</a>
</button><br>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form>
<label>First Name: </label>
<input id="first_name" type="text" name="first_name" max length="50" required/>
<label>Last Name: </label>
<input id="last_name" type="text" name="last_name" max length="100" required/>
<label>Age: </label>
<input id="age" type="number" name="age" required/>
<label>Nationality: </label>
<input id="nationality" type="text" name="nationality" required/>
<label>Bio: </label>
<input id="bio" type="text" name="bio" required/>
</form>
<button type="button">
<a href="/bookshelf/authors/{{ author.id }}/details/">
Add Author
</a>
</button><br>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<form>
<label>Title: </label>
<input id="title" type="text" name="title" max length="50" required/>
<label>Author: </label>
<input id="author" type="text" name="author" max length="100" required/>
<label>Publisher: </label>
<input id="publisher" type="text" name="publisher" required/>
<label>Year Published: </label>
<input id="year_published" type="number" name="year_published" required/>
<label>ISBN: </label>
<input id="ISBN" type="number" name="ISBN" required/>
<label>Blurb: </label>
<input id="blurb" type="text" name="blurb" required/>
</form>
<button type="button">
<a href="/bookshelf/books/{{ book.id }}/details/">
Add Book
</a>
</button><br>
{% endblock %}
\ No newline at end of file
......@@ -8,8 +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('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-books'),
path('books/<int:id>/edit/', BookDetailView.as_view(), name='edit-books'),
]
app_name = 'bookshelf'
\ No newline at end of file
......@@ -3,6 +3,7 @@ from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Author, Books
from.forms import AuthorForm, BookForm
# Create your views here.
......@@ -17,14 +18,16 @@ class AuthorView(ListView):
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):
first_name = request.POST.get('first_name')
last_name = request.POST.get('last_name')
age = request.POST.get('age')
nationality = request.POST.get('nationality')
bio = request.POST.get('bio')
return self.get(request, *args, **kwargs)
form = AuthorForm(request.POST)
if form.is_valid():
return self.get(request, *args, **kwargs)
else:
return render(request, self.template_name, {'form': form})
class AuthorDetailView(DetailView):
......@@ -40,15 +43,16 @@ class BooksView(ListView):
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):
title = request.POST.get('title')
author = request.POST.get('author')
publisher = request.POST.get('apublisherge')
year_published = request.POST.get('year_published')
ISBN = request.POST.get('ISBN')
blurb = request.POST.get('blurb')
return self.get(request, *args, **kwargs)
form = BookForm(request.POST)
if form.is_valid():
return self.get(request, *args, **kwargs)
else:
return render(request, self.template_name, {'form': form})
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