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 @@
<li><a href="#">Home</a></li>
<li><a href="/bookshelf/books">Books</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 %}
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 = [
path('',index,name='index'),
path('home/',home,name='home'),
path('books/',BooksView.as_view(),name='books'),
path('authors/',AuthorsView.as_view(),name='authors'),
path('books/<int:pk>/details/',BookDetailView.as_view(),name='book_details'),
path('authors/<int:pk>/details/',AuthorDetailView.as_view(),name='author_details')
path('', index, name='index'),
path('home/', home, name='home'),
path('books/', BooksView.as_view(), name='books'),
path('authors/', AuthorsView.as_view(), name='authors'),
path('books/<int:pk>/details/', BookDetailView.as_view(), name='book_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"
from django.shortcuts import render
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
def index(request):
return HttpResponse('honk honk')
def home(request):
return render(request, 'bookshelf/home.html', {'name': 'home'})
class BooksView(ListView):
model = Book
template_name = 'bookshelf/books.html'
class BookDetailView(DetailView):
model = Book
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):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
......@@ -10,6 +10,10 @@
color: white;
text-decoration-style: solid;
}
form {
margin: 0 auto;
width:300px;
}
</style>
<title>{% block title %}My amazing site{% endblock %}</title>
<nav class="navbar navbar-custom">
......@@ -34,12 +38,13 @@
<div class="text-left">
{% block content %}{% endblock %}
</div>
<div class="text-right">
<figure class="form form">
{% block form %}{% endblock %}
</figure>
</div>
</div>
</figure>
</figure>
</div>
<br><br><br>
{% block scripts %}{% endblock %}
</body>
</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