Commit 7e8679f1 authored by rachbit's avatar rachbit

implemented user forms in add-book.html

parent 50c99387
from django import forms
from .models import Books
class BookForm(forms.Form):
class Meta:
model = Books
fields = '__all__'
{% extends 'base.html' %}
{% load static %}
{% block title %}Add a Book{% endblock %}
{% block header %}
<cite><h1 class="text-center">Hindi pa ba ako sapat?</h1></cite>
{% endblock %}
{% block subtitle %}
<p class="text-center">
feel free to add more books to my collection.<br>
-
</p>
{% endblock %}
<div class="text-center">
</div>
{% block form %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
</div>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<div class="text-center">
<br>
<br>
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
</div>
{% endblock %}
...@@ -21,4 +21,6 @@ ...@@ -21,4 +21,6 @@
<li><a href="#">Home</a></li> <li><a href="#">Home</a></li>
<li><a href="/bookshelf/books">Books</a></li> <li><a href="/bookshelf/books">Books</a></li>
<li><a href="/bookshelf/authors">Authors</a></li> <li><a href="/bookshelf/authors">Authors</a></li>
<li><a href="/bookshelf/books/add">Add Book</a></li>
<li><a href="#">Add Author</a></li>
{% endblock %} {% endblock %}
from django.urls import path from django.urls import path
from .views import index, home, BooksView, AuthorsView, BookDetailView, AuthorDetailView from .views import index, home, BooksView, AuthorsView, BookDetailView, AuthorDetailView, BookCreateView, BookUpdateView
urlpatterns = [ urlpatterns = [
path('',index,name='index'), path('', index, name='index'),
path('home/',home,name='home'), path('home/', home, name='home'),
path('books/',BooksView.as_view(),name='books'), path('books/', BooksView.as_view(), name='books'),
path('authors/',AuthorsView.as_view(),name='authors'), path('authors/', AuthorsView.as_view(), name='authors'),
path('books/<int:pk>/details/',BookDetailView.as_view(),name='book_details'), path('books/<int:pk>/details/', BookDetailView.as_view(), name='book_details'),
path('authors/<int:pk>/details/',AuthorDetailView.as_view(),name='author_details') path('authors/<int:pk>/details/',
AuthorDetailView.as_view(), name='author_details'),
path('books/add/', BookCreateView.as_view(), name='add-book'),
path('books/<int:pk>/edit/', BookUpdateView.as_view(), name='edit-book'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView, CreateView, UpdateView
from .models import Author, Book from .models import Author, Book
def index(request): def index(request):
return HttpResponse('honk honk') return HttpResponse('honk honk')
def home(request): def home(request):
return render(request, 'bookshelf/home.html', {'name': 'home'}) return render(request, 'bookshelf/home.html', {'name': 'home'})
class BooksView(ListView): class BooksView(ListView):
model = Book model = Book
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
class BookDetailView(DetailView): class BookDetailView(DetailView):
model = Book model = Book
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.html'
class BookCreateView(CreateView):
model = Book
fields = '__all__'
template_name = "bookshelf/add-book.html"
class BookUpdateView(UpdateView):
model = Book
fields = '__all__'
template_name = "bookshelf/edit-book.html"
class AuthorsView(ListView): class AuthorsView(ListView):
model = Author model = Author
template_name = 'bookshelf/authors.html' template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
color: white; color: white;
text-decoration-style: solid; text-decoration-style: solid;
} }
form {
margin: 0 auto;
width:300px;
}
</style> </style>
<title>{% block title %}My amazing site{% endblock %}</title> <title>{% block title %}My amazing site{% endblock %}</title>
<nav class="navbar navbar-custom"> <nav class="navbar navbar-custom">
...@@ -34,12 +38,13 @@ ...@@ -34,12 +38,13 @@
<div class="text-left"> <div class="text-left">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
<div class="text-right">
<figure class="form form">
{% block form %}{% endblock %}
</figure>
</div>
</div> </div>
</figure> </figure>
</figure> </figure>
</div>
<br><br><br>
{% block scripts %}{% endblock %}
</body> </body>
</html> </html>
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