Commit 02bd157e authored by Caryn Lopez-Go's avatar Caryn Lopez-Go

completed code for all

parent 872273c0
Pipeline #3069 failed with stages
from django.contrib import admin
from .models import Author, Books
# Register your models here.
class BooksInLine(admin.TabularInline):
model = Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio')
search_fields = ('first_name', 'last_name', 'age', 'nationality')
inlines = [BooksInLine]
class BooksAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'publisher', 'ISBN', 'year_published')
def get_name(self, obj):
return obj.article.title
get_name.short_description = 'title'
get_name.admin_order_field = 'year_published'
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
\ No newline at end of file
from django.apps import AppConfig
class BookshelfConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'bookshelf'
# Generated by Django 3.2 on 2023-03-28 13:12
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
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(max_length=50)),
('last_name', models.CharField(max_length=50)),
('age', models.IntegerField(default=0)),
('nationality', models.CharField(max_length=50)),
('bio', models.TextField(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(max_length=100)),
('publisher', models.CharField(max_length=100)),
('year_published', models.IntegerField(default=0)),
('ISBN', models.IntegerField(default=0, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(9999999999999)])),
('blurb', models.TextField(max_length=700)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
from django.db import models
from django.core.validators import MaxValueValidator, MinValueValidator
from django.urls import reverse
# Create your models here.
class Author(models.Model):
first_name = models.CharField(max_length = 50)
last_name = models.CharField(max_length = 50)
age = models.IntegerField(default = 0)
nationality = models.CharField(max_length = 50)
bio = models.TextField(max_length = 700)
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author-details', kwargs={'pk':self.pk})
class Books(models.Model):
title = models.CharField(max_length = 100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length = 100)
year_published = models.IntegerField(default = 0)
ISBN = models.IntegerField(default = 0000000000000, validators=[MinValueValidator(0000000000000), MaxValueValidator(9999999999999)])
blurb = models.TextField(max_length = 700)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk':self.pk})
{% extends 'base.html' %}
{% block title %}{{ author.first_name }} {{ author.last_name }}{% endblock %}
{% block content %}
<h1>{{ author.first_name }} {{ author.last_name }}</h1>
<p>
{{ author.age }}<br>
{{ author.nationality }}<br>
{{ author.bio }}<br>
Books by {{ author.first_name }} {{ author.last_name }} I love:
</p>
<ul>
{% for books in author.books_set.all %}
<li>
<a href="{{ books.get_absolute_url }}">{{ books.title }}</a>
</li>
{% endfor %}
</ul>
<section class="bottom">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</section>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Caryn's Favorite Authors:</h1>
<ul>
{% for author in author_list %}
<li>
<a href="{{ author.get_absolute_url }}"> {{ author }}</a>
</li>
{% endfor %}
</ul>
<section class="bottom">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
</section>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ books.title }}{% endblock %}
{% block content %}
<h1>{{ books.title }}</h1>
<p>
<a href="{{ books.author.get_absolute_url }}">{{ books.author }}</a><br>
{{ books.publisher }}<br>
{{ books.year_published }}<br>
{{ books.ISBN }}<br>
{{ books.blurb }}<br>
</p>
<section class="bottom">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</section>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Caryn's Favorite Books:</h1>
<ul>
{% for book in books_list %}
<li>
<a href="{{ book.get_absolute_url }}"> {{ book }}</a>
</li>
{% endfor %}
</ul>
<section class="bottom">
<a href="{% url 'bookshelf:home' %}">Home</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</section>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}My Favorite Books & Authors{% endblock %}
{% block content %}
<h1>Welcome to Caryn's Database of Favorite Books and Authors!</h1>
<p>I like young adult and mystery books.</p>
<section class="bottom">
<a href="{% url 'bookshelf:books' %}">Books</a>
<a href="{% url 'bookshelf:authors' %}">Authors</a>
</section>
{% endblock %}
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
from .views import *
urlpatterns = [
path('home/', home, name = "home"),
path('authors/', AuthorsListView.as_view(), name = "authors"),
path('authors/<int:pk>/details', AuthorDetailsView.as_view(), name = "author-details"),
path('books/', BooksListView.as_view(), name = "books"),
path('books/<int:pk>/details', BookDetailsView.as_view(), name = "book-details")
]
app_name = 'bookshelf'
\ No newline at end of file
from django.template import loader
from django.shortcuts import render
from django.http import HttpResponse
from .models import Author, Books
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
# Create your views here.
def home(request):
return render(request, 'bookshelf/home.html')
class BooksListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BookDetailsView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorsListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailsView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
\ No newline at end of file
......@@ -32,7 +32,7 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'bookshelf'
'bookshelf.apps.BookshelfConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -120,6 +120,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
......
......@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('bookshelf/', include("bookshelf.urls")),
path('', include("bookshelf.urls")),
path('admin/', admin.site.urls)
]
\ No newline at end of file
File added
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap');
body {
background-color: #7d3573 ;
color: #fcfaf4;
font-family: 'Poppins', sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
h1{
font-size: xx-large;
}
p{
font-size: larger;
}
a{
color: darkorange;
text-decoration: none;
}
li{
list-style-type: none;
}
.bottom{
display: flex;
align-items: center;
justify-content: space-between;
}
.bottom a{
color: white;
border-radius: 10px;
padding: 10px 20px;
background: darkorange;
font-size: large;
text-decoration: none;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href=" {% static '/style.css' %}"/>
<title>{% block title %}My Favorite Books & Authors{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
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