Commit 3dccf9d2 authored by John Riz Daniel Ramos's avatar John Riz Daniel Ramos

Merge branch 'readingv1'

parents 374ce075 756a16e8
Pipeline #3067 canceled with stages
#ignores .env file for SECRET_KEY
.env
#ignores midtermenv virtual env
midtermenv/
.DS_Store
*.pyc
from django.contrib import admin
from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio')
class BooksAdmin(admin.ModelAdmin):
model = Books
list_display = ('title', 'author','publisher','year_published', 'ISBN', 'blurb')
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 4.1.7 on 2023-03-27 14:16
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=100)),
('last_name', models.CharField(max_length=100)),
('age', models.IntegerField()),
('nationality', models.CharField(max_length=50)),
('bio', models.TextField(max_length=700)),
],
),
migrations.CreateModel(
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('publisher', models.CharField(max_length=50)),
('year_published', models.IntegerField(max_length=4)),
('ISBN', models.IntegerField(max_length=13)),
('blurb', models.TextField(max_length=200)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
# Generated by Django 4.1.7 on 2023-03-27 14:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='ISBN',
field=models.IntegerField(),
),
migrations.AlterField(
model_name='widgetuser',
name='year_published',
field=models.IntegerField(),
),
]
# Generated by Django 4.1.7 on 2023-03-27 14:24
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0002_alter_widgetuser_isbn_and_more'),
]
operations = [
migrations.RenameModel(
old_name='WidgetUser',
new_name='Books',
),
]
from django.db import models
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
age = models.IntegerField()
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 f"{self.pk}"
class Books(models.Model):
title = models.CharField(max_length=50)
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
publisher = models.CharField(max_length=50)
year_published = models.IntegerField()
ISBN = models.IntegerField()
blurb = models.TextField(max_length=1200)
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return f"{self.pk}"
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import home_view, BooksListView, BooksDetailView, AuthorsView, AuthorsDetailView
urlpatterns = [
path('home/', home_view, name='home_view'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/', AuthorsView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
]
app_name = "bookshelf"
\ No newline at end of file
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Author, Books
def home_view(request):
return render(request, 'home.html', {'name': 'Daniel'})
class BooksListView(ListView):
model = Books
template_name = "bookshelf/books.html"
class BooksDetailView(DetailView):
model = Books
template_name = "bookshelf/book_detais.html"
class AuthorsView(ListView):
model = Author
template_name = "bookshelf/authors.html"
class AuthorsDetailView(DetailView):
model = Author
template_name = "bookshelf/author_details.html"
\ No newline at end of file
......@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookshelf',
]
MIDDLEWARE = [
......@@ -58,7 +59,7 @@ ROOT_URLCONF = 'danielramos_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path
urlpatterns = [
path('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<title>{% block title %}{% 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
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.first_name}} {{ object.last_name}}{% endblock %}
{% block content %}
<h1>{{ object.first_name}} {{ object.last_name}}</h1>
<p>
Age: {{ object.age }}<br>
Nationality: {{ object.nationality }}<br><br>
<i>{{ object.bio }}</i>
</p>
<h2>Books by {{ object.first_name}} {{ object.last_name}} I love:</h2>
{% for book in object.books.all %}
<li>
<a href="/books/{{ book.get_absolute_url }}/details/"> {{ book.title }}</a>
</li>
{% endfor %}
<br>
<br>
<br>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<h1>Daniel's Favorite Authors:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}/details/">{{ object.first_name }} {{ object.last_name }}</a>
</li>
{% endfor %}
</ul>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<p>
by <a href="/authors/{{ object.author.get_absolute_url }}/details/">{{ object.author }}</a><br>
Publisher: {{ object.publisher }}<br>
Published: {{ object.year_published }}<br>
ISBN: {{ object.ISBN }}<br><br>
<i>{{ object.blurb }}</i>
</p>
<br>
<br>
<br>
<a href="/home">Home</a>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>Daniel's Favorite Books:</h1>
<ul>
{% for object in object_list %}
<li>
<a href="{{ object.get_absolute_url }}/details/">{{ object.title }}</a>
</li>
{% endfor %}
</ul>
<a href="/home">Home</a>
<a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}My Favorite Books and Authors{% endblock %}
{% block content %}
<h1>Welcome to {{ name }}'s Database of Favorite Books and Authors!</h1>
<p>I haven't read a single novel in my life under my own volition. I do not like to read, I have read none of the books that are present in the database. I have watched videos on why I should read them though. So with that in mind, I also don't have a favorite genre or author. If this database were a literary genre it would be classified as fiction.</p>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
{% endblock %}
\ 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