Adding entire project again after vscode-gitlab sync error

parent d3859fa9
Pipeline #3113 failed with stages
......@@ -5,4 +5,4 @@ Lab 03: My Favorite Books and Authors
Date of submission: March 28, 2023
I, Al Vincent E. Bomediano hereby state that this code has been written by me, and only me.
<alvin> Al Vincent E. Bomediano, 28/03/2023
\ No newline at end of file
<alvin> Al Vincent E. Bomediano, 30/03/2023
\ No newline at end of file
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.1/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -55,7 +56,7 @@ ROOT_URLCONF = 'albomediano_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -116,7 +117,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
......
......@@ -18,6 +18,6 @@ from django.urls import include, path
urlpatterns = [
path('bookshelf/', include('bookshelf.urls', namespace="bookshelf")),
path('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
from django.contrib import admin
from .models import Author, Books
# Register your models here.
class AuthorAdmin(admin.ModelAdmin):
model = Author
search_fields = ('first_name', 'last_name',)
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio', )
list_filter = ('first_name', 'last_name', 'age', 'nationality', 'bio', )
class BooksAdmin(admin.ModelAdmin):
model = Books
search_fields = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb', )
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb', )
list_filter = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb', )
admin.site.register(Author, AuthorAdmin)
admin.site.register(Books, BooksAdmin)
# Generated by Django 4.1.7 on 2023-03-30 13:59
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=100)),
('bio', models.CharField(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(max_length=4)),
('ISBN', models.IntegerField(max_length=13)),
('blurb', models.CharField(max_length=200)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
]
from django.db import models
from django.urls import reverse
class Author(models.Model):
......@@ -8,11 +9,23 @@ class Author(models.Model):
nationality = models.CharField(max_length=100)
bio = models.CharField(max_length=700)
def __str__(self):
return '{}, {}'.format(self.last_name, self.first_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.CharField(max_length=100) # from author model
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=100)
year_published = models.IntegerField(max_length=4)
ISBN = models.IntegerField(max_length=13)
blurb = models.CharField(max_length=200)
def __str__(self):
return '{} by {}'.format(self.title, self.author)
def get_absolute_url(self):
return reverse('bookshelf:book-details', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% load static%}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>{{ object.author }}</h1>
{{ object.first_name }} {{ object.last_name }}<br>
{{ object.nationality }}<br>
{{ object.bio }}<br>
<br>
Books by {{ object.first_name }} {{ objects.last_name }} I like:
<br>
{% for object in author.books_set.all %}
<a href="{{ object.get_absolute_url }}">{{ object }}<br></a>
{% endfor %}
<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 %}Authors I follow{% endblock %}
{% block content %}
<h1>Al's Favorite Authors:</h1>
{% for object in object_list %}
<a href="{{ object.get_absolute_url }}">{{ object.first_name }} {{ object.last_name}}<br></a>
{% endfor %}
<br>
<a href="/home">Home</a> <a href="/books">Books</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static%}
{% block title %}My Favorite Books{% endblock %}
{% block content %}
<h1>{{ object.title }}</h1>
<a href="/authors/{{ object.author.pk }}/details">{{ object.author}}</a>
<br>
{{ object.publisher }}<br>
{{ object.year_published }}<br>
{{ object.ISBN }}<br>
{{ object.blurb }}<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>Al's Favorite Books:</h1>
{% for object in object_list %}
<a href="{{ object.get_absolute_url }}">{{ object.title }}<br></a>
{% endfor %}
<br>
<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 & Authors{% endblock %}
{% block content %}
<h1>Welcome to Al's Database of
Favorite Books and Authors</h1>
<h3>I barel read books, and when I do, they are mostly Japanese Light Novels or Manga. But recently I have been into Webtoons!</h3>
<a href="/books">Books</a> <a href="/authors">Authors</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from .views import index
from .import views
from .views import (
BooksView, BooksDetailsView,
AuthorsView, AuthorsDetailsView
)
urlpatterns = [
path('', index, name='index'),
path('home/', views.home_view, name='home'),
path('books/', BooksView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailsView.as_view(), name='book-details'),
path('authors/', AuthorsView.as_view(), name='authors-list'),
path('authors/<int:pk>/details', AuthorsDetailsView.as_view(), name='author-details'),
]
# This might be needed, depending on your Django version
app_name = "bookshelf"
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Books, Author
def index(request):
return HttpResponse('Hello World! This came from the index view')
def home_view(request):
return render(request, 'bookshelf/home.html')
class BooksView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetailsView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorsView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorsDetailsView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
<html lang="en">
<head>
{% block title %}<title>Insert Title</title>{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</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