Commit 6fdf11c7 authored by enricosuplico's avatar enricosuplico

added bookshelf

parent af1e3a6e
from django.contrib import admin
from .models import Author, Books
# Register your models here.
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio')
search_display = ('last_name')
list_filter = ('last_name',)
class BooksAdmin(admin.ModelAdmin):
model = Books
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb')
search_display = ('title', 'author', 'publisher', 'year_published', 'ISBN')
list_filter = ('title',)
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bookshelf'
# Generated by Django 3.2 on 2023-04-27 14:33
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Author',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(default='', max_length=100)),
('last_name', models.CharField(default='', max_length=100)),
('age', models.IntegerField(default=0)),
('nationality', models.CharField(default='', max_length=25)),
('bio', models.TextField(default='', max_length=700)),
],
),
migrations.CreateModel(
name='Books',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='', max_length=100)),
('author', models.CharField(default='', max_length=100)),
('publisher', models.CharField(default='', max_length=100)),
('year_published', models.IntegerField(default=0)),
('ISBN', models.IntegerField(default=0)),
('blurb', models.TextField(default='', max_length=200)),
],
),
]
# Generated by Django 3.2 on 2023-04-27 15:09
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='books',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author'),
),
]
from django.db import models
from django.urls import reverse
# Create your models here.
class Author (models.Model):
first_name = models.CharField(max_length = 100, default = "")
last_name = models.CharField(max_length = 100, default = "")
age = models.IntegerField(default = 0)
nationality = models.CharField(max_length = 25, default = "")
bio = models.TextField(max_length = 700, default = "")
def __str__(self):
return self.last_name
def get_absolute_url(self):
return reverse('author-details', kwargs={'pk':self.pk})
class Books (models.Model):
title = models.CharField(max_length = 100, default = "")
author = models.ForeignKey(Author, on_delete = models.CASCADE)
publisher = models.CharField(max_length = 100, default = "")
year_published = models.IntegerField(default = 0)
ISBN = models.IntegerField(default = 0)
blurb = models.TextField(max_length = 200, default = "")
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('book-details', kwargs={'pk':self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Authors {% endblock %}
{% block content %}
<h1>Enrico's Favorite Authors:</h1>
<body>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.first_name }} {{ object.last_name }} </a>
</li>
{% endfor %}
</body>
<footer>
<br> <br>
<a href="/bookshelf/home">Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/books">Books</a>
</footer>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.first_name }} {{ object.last_name }} {% endblock %}
{% block content %}
<h1> {{ object.first_name }} {{ object.last_name }} </h1>
<body>
{{ object.age }}<br>
{{ object.nationality }}<br>
{{ object.bio }}<br><br>
Books by {{ object.first_name }} {{ object.last_name }} I love: <br>
{% for object in author.books_set.all %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.title }}</a>
</li>
{% endfor %}
</body>
<footer>
<br><br>
<a href="/bookshelf/home">Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/books">Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/authors">Authors
</footer>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books {% endblock %}
{% block content %}
<h1>Enrico's Favorite Books:</h1>
<body>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}">{{ object.title }}</a>
</li>
{% endfor %}
</body>
<footer>
<br><br>
<a href="/bookshelf/home">Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/authors">Authors</a>
</footer>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<body>
<a href="{{ object.author.get_absolute_url }}">
{{ object.author.first_name }} {{ object.author.last_name }}<br>
</a>
{{ object.publisher }}<br>
{{ object.year_published }}<br>
{{ object.ISBN }}<br>
{{ object.blurb }}
</body>
<footer>
<br><br>
<a href="/bookshelf/home">Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/books">Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/authors">Authors
</footer>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} My Favorite Books & Authors {% endblock %}
{% block content %}
<h1> Welcome to Enrico's Database of Favorite Books and Authors! </h1>
<body> The kind of Genres I enjoy from books are those that I can imagine in my head.
<br> It makes me feel as if I am part of the story.
<br> I like authors who write well and are able to paint the image they want inside their reader's head.
<br> <br>
</body>
<footer>
<a href="/bookshelf/books">Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/bookshelf/authors">Authors</a>
</footer>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import Homepage_View, Books_List_View, Books_Detail_View, Authors_List_View, Authors_Detail_View
urlpatterns = [
path('home/', Homepage_View, name='home'),
path('books/', Books_List_View.as_view(), name='books-list'),
path('books/<int:pk>/details/', Books_Detail_View.as_view(), name='book-details'),
path('authors/', Authors_List_View.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', Authors_Detail_View.as_view(), name='author-details'),
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from django.views import View
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
def Homepage_View(request):
return render(request, 'bookshelf/home.html')
class Books_List_View(ListView):
models = Books
template_name = 'bookshelf/books.html'
class Books_Detail_View(DetailView):
model = Books
template_name = 'bookshelf/books_details.html'
class Authors_List_View(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class Authors_Detail_View(DetailView):
model = Author
template_name = 'bookshelf/author_details.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