Commit 5ba2dfc3 authored by rachbit's avatar rachbit

added edit-author and add-author

parent ba420ee3
from django import forms from django import forms
from .models import Books from .models import Books, Authors
class BookForm(forms.Form): class BookForm(forms.Form):
class Meta: class Meta:
model = Books model = Books
fields = '__all__' 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 @@ ...@@ -22,3 +22,10 @@
</form> </form>
</div> </div>
{% endblock %} {% 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> ...@@ -28,6 +28,13 @@ read between their lines<br>
</div> </div>
</ul> </ul>
<br> <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> <h2>Books by {{object.first_name}} {{object.last_name}} that I love:</h2>
<ul> <ul>
{% for book in object.books.all %} {% for book in object.books.all %}
...@@ -41,4 +48,6 @@ read between their lines<br> ...@@ -41,4 +48,6 @@ read between their lines<br>
<li><a href="/bookshelf/home">Home</a></li> <li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %} {% endblock %}
...@@ -30,4 +30,6 @@ ...@@ -30,4 +30,6 @@
<li><a href="/bookshelf/home">Home</a></li> <li><a href="/bookshelf/home">Home</a></li>
<li><a href="/bookshelf/books">Books</a></li> <li><a href="/bookshelf/books">Books</a></li>
<li><a href="#">Authors</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 %} {% endblock %}
...@@ -27,7 +27,7 @@ fundamental.<br> ...@@ -27,7 +27,7 @@ fundamental.<br>
</ul> </ul>
<br> <br>
<div class="text-center"> <div class="text-center">
<form action="edit"> <form action="edit/{{ object.book.get_absolute_url }}">
<input type="submit" value="Edit Book"> <input type="submit" value="Edit Book">
</form> </form>
</div> </div>
...@@ -37,4 +37,6 @@ fundamental.<br> ...@@ -37,4 +37,6 @@ fundamental.<br>
<li><a href="/bookshelf/home">Home</a></li> <li><a href="/bookshelf/home">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %} {% endblock %}
...@@ -28,4 +28,6 @@ ...@@ -28,4 +28,6 @@
<li><a href="/bookshelf/home">Home</a></li> <li><a href="/bookshelf/home">Home</a></li>
<li><a href="#">Books</a></li> <li><a href="#">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="/bookshelf/authors/add">Add Author</a></li>
{% endblock %} {% 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 @@ ...@@ -15,10 +15,18 @@
</div> </div>
{% block form %} {% block form %}
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {% for field in form %}
<input type="submit" value="Save Changes"> {{field.label}}:{{field}} <br><br>
</form> {% endfor %}
</div> <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 %} {% endblock %}
...@@ -22,5 +22,5 @@ ...@@ -22,5 +22,5 @@
<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="/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 %} {% 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 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 = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
...@@ -10,7 +10,9 @@ urlpatterns = [ ...@@ -10,7 +10,9 @@ urlpatterns = [
path('authors/<int:pk>/details/', path('authors/<int:pk>/details/',
AuthorDetailView.as_view(), name='author_details'), AuthorDetailView.as_view(), name='author_details'),
path('books/add/', BookCreateView.as_view(), name='add-book'), 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" app_name = "bookshelf"
...@@ -35,6 +35,18 @@ class BookUpdateView(UpdateView): ...@@ -35,6 +35,18 @@ class BookUpdateView(UpdateView):
template_name = "bookshelf/edit-book.html" 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): class AuthorsView(ListView):
model = Author model = Author
template_name = 'bookshelf/authors.html' template_name = 'bookshelf/authors.html'
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
</figure> </figure>
</figure> </figure>
</body> </body>
<br><br><br>
<nav class="navbar navbar-custom"> <nav class="navbar navbar-custom">
<div class="container-center"> <div class="container-center">
<ul class="nav navbar-nav navbar-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