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

edited all 4 forms htmls

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