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

created forms.py

parent eb95db7f
from django import forms
from django.db import models
from models import Author
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
class AuthorForm(forms.Form):
first_name = forms.CharField(label='first_name', max_length=50)
last_name = forms.CharField(label='last_name', max_length=50)
age = forms.IntegerField(label='age')
nationality = forms.CharField(label='nationality', max_length=50)
bio = forms.TextField(label='bio', max_length=700)
class BookForm(forms.Form):
title = forms.CharField(label='title', max_length=50)
author = forms.ForeignKey(Author, on_delete=models.CASCADE)
publisher = forms.CharField(label='publisher', max_length=50)
year_published = forms.IntegerField(label='year_published', max_length=50)
ISBN = forms.CharField(label='ISBN', max_length=50)
blurb = forms.CharField(label='blurb', max_length=50)
\ No newline at end of file
<form>
<label>Full Name: </label>
<input id="name" type="text" name="section" max length="100" required/>
<label>Full Name: </label>
<input id="section" type="text" name="section" max length="100" required/>
<label>Full Name: </label>
<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="age" type="number" name="age" required/>
<label>Year Published: </label>
<input id="age" type="number" name="age" required/>
<label>ISBN: </label>
<input id="age" type="number" name="age" required/>
<label>Blurb: </label>
<input id="age" type="number" name="age" required/>
</form>
\ No newline at end of file
......@@ -17,6 +17,15 @@ 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 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)
class AuthorDetailView(DetailView):
pk_url_kwarg = 'id'
......@@ -31,6 +40,15 @@ 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 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)
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