Commit b412220b authored by Stefan Gomez's avatar Stefan Gomez

Added a link to add books in the Homepage and created the appropriate "Add New...

Added a link to add books in the Homepage and created the appropriate "Add New Books " page respectively.
parent 8dabbfb2
......@@ -2,6 +2,7 @@ from django.contrib import admin
from.models import Author, Book
class AuthorAdmin(admin.ModelAdmin):
model = Author
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
{% block footer %}{% endblock %}
\ No newline at end of file
......@@ -9,4 +9,7 @@
To be honest I am not really a book kind of guy. Why read a book when you can just watch instead you feel me? Nevertheless I do prefer to read fictional fantasy kind of books such as that of mainly the Harry Potter and Percy Jackson books. With that in mind I personally look up to Rick Riordan because J.K Rowling has a bunch of controversies while Rick Riordan just seems like a down to earth kind of guy. </p>
{% endblock %}
{% block footer %}<a href="/books">Books</a> | <a href="/authors">Authors</a>{% endblock %}
\ No newline at end of file
{% block footer %}
<a href="/books">Books</a> | <a href="/authors">Authors
<br><a href="/books/add">Add Book</a>
</a>{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import home, BooksView, PerBooksView, AuthorsView, PerAuthorsView
from .views import home, BooksView, PerBooksView, AddBooksView, AuthorsView, PerAuthorsView
urlpatterns = [
path('home', home, name='home'),
path('books', BooksView.as_view(), name='books'),
path('books/<int:pk>/details', PerBooksView.as_view(), name='book-detail'),
path('books/add/', AddBooksView.as_view(), name='add-book'),
path('authors', AuthorsView.as_view(), name='authors'),
path('authors/<int:pk>/details', PerAuthorsView.as_view(), name='author-detail')
]
......
from django.shortcuts import render
from django.views import View
from .models import Author, Book
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import Author, Book
def home(request):
return render(request, 'bookshelf/home.html')
......@@ -18,6 +20,12 @@ class PerBooksView(DetailView):
template_name = 'bookshelf/book_details.html'
class AddBooksView(CreateView):
model = Book
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorsView(ListView):
model = Author
template_name = 'bookshelf/authors.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