Commit 5ba2dfc3 authored by rachbit's avatar rachbit

added edit-author and add-author

parent ba420ee3
from django import forms
from .models import Books
from .models import Books, Authors
class BookForm(forms.Form):
class Meta:
model = Books
fields = '__all__'
class AuthorForm(forms.Form):
class Meta:
model = Authors
fields = '__all__'
{% extends 'base.html' %}
{% load static %}
{% block title %}Add an Author{% 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 authors 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 Author">
</form>
</div>
{% endblock %}
{% block navbar %}
<li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -22,3 +22,10 @@
</form>
</div>
{% endblock %}
{% block navbar %}
<li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -28,6 +28,13 @@ read between their lines<br>
</div>
</ul>
<br>
<div class="text-center">
<form action="edit">
<input type="submit" value="Edit Author">
</form>
</div>
<br>
<br>
<h2>Books by {{object.first_name}} {{object.last_name}} that I love:</h2>
<ul>
{% for book in object.books.all %}
......@@ -41,4 +48,6 @@ read between their lines<br>
<li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -30,4 +30,6 @@
<li><a href="/bookshelf/home">Home</a></li>
<li><a href="/bookshelf/books">Books</a></li>
<li><a href="#">Authors</a></li>
<li><a href="/bookshelf/books/add">Add Book</a></li>
<li><a href="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -27,7 +27,7 @@ fundamental.<br>
</ul>
<br>
<div class="text-center">
<form action="edit">
<form action="edit/{{ object.book.get_absolute_url }}">
<input type="submit" value="Edit Book">
</form>
</div>
......@@ -37,4 +37,6 @@ fundamental.<br>
<li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -28,4 +28,6 @@
<li><a href="/bookshelf/home">Home</a></li>
<li><a href="#">Books</a></li>
<li><a href="/bookshelf/authors">Authors</a></li>
<li><a href="/bookshelf/books/add">Add Book</a></li>
<li><a href="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block header %}
<cite><h1 class="text-center">May pagkakamali ba ako?</h1></cite>
{% endblock %}
{% block subtitle %}
<p class="text-center">
feel free to edit author details in my collection.<br>
-
</p>
{% endblock %}
<div class="text-center">
</div>
{% block form %}
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
{% block navbar %}
<li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -15,10 +15,18 @@
</div>
{% block form %}
<form method="post">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
</div>
</form>
{% endblock %}
{% block navbar %}
<li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
......@@ -22,5 +22,5 @@
<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>
<li><a href="/bookshelf/authors/add">Add Author</a></li>
{% endblock %}
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('Welcome to Rachel’s Music Library!')
from django.urls import path
from .views import index, home, BooksView, AuthorsView, BookDetailView, AuthorDetailView, BookCreateView, BookUpdateView
from .views import index, home, BooksView, AuthorsView, BookDetailView, AuthorDetailView, BookCreateView, BookUpdateView, AuthorCreateView, AuthorUpdateView
urlpatterns = [
path('', index, name='index'),
......@@ -10,7 +10,9 @@ urlpatterns = [
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'),
path('books/<int:pk>/details/edit/', BookUpdateView.as_view(), name='edit-book'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:pk>/details/edit/', AuthorUpdateView.as_view(), name='edit-author'),
]
app_name = "bookshelf"
......@@ -35,6 +35,18 @@ class BookUpdateView(UpdateView):
template_name = "bookshelf/edit-book.html"
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = "bookshelf/add-author.html"
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = "bookshelf/edit-author.html"
class AuthorsView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
......
......@@ -51,6 +51,7 @@
</figure>
</figure>
</body>
<br><br><br>
<nav class="navbar navbar-custom">
<div class="container-center">
<ul class="nav navbar-nav navbar-center">
......
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