Commit 5511a2d6 authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

homepage finally works

parent 8b91d64c
# app/admin.py
from django.contrib import admin
from .models import Author,Book
from .models import Author,Books
class AuthorAdmin(admin.ModelAdmin):
......@@ -18,4 +18,4 @@ class BookAdmin(admin.ModelAdmin):
# registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified
admin.site.register(Author, AuthorAdmin)
admin.site.register(Book, BookAdmin)
admin.site.register(Books, BookAdmin)
# Generated by Django 3.2 on 2023-03-28 13:53
import datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='book',
name='year_published',
field=models.DateField(default=datetime.datetime(2023, 3, 28, 21, 53, 0, 569351)),
),
]
# Generated by Django 3.2 on 2023-03-29 02:51
import datetime
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bookshelf', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Books',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(blank=True, max_length=50)),
('publisher', models.CharField(blank=True, max_length=50)),
('year_published', models.DateField(default=datetime.datetime(2023, 3, 29, 10, 51, 31, 682472))),
('ISBN', models.CharField(default='0000000000000', max_length=50, unique=True)),
('blurb', models.TextField(blank=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='bookshelf.author')),
],
),
migrations.DeleteModel(
name='Book',
),
]
from django.db import models
import datetime
from django.urls import reverse
class Author(models.Model):
first_name = models.CharField(max_length=50, blank=True)
......@@ -11,8 +12,11 @@ class Author(models.Model):
def __str__(self):
return "{} {}".format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse()
class Book(models.Model):
class Books(models.Model):
title = models.CharField(max_length=50, blank=True)
author = models.ForeignKey(
Author,
......@@ -25,3 +29,6 @@ class Book(models.Model):
def __str__(self):
return self.title
def get_absolute_url(self):
return self.pk
\ No newline at end of file
<head>
</head>
<body>
<h1>{% block title %}{% endblock %}</h1>
{% block additional %}{% endblock %}
<div>{% block content %}{% endblock %}</div>
</body>
\ No newline at end of file
{% extends 'base.html' %}
{% block title %} My favorite Books and Authors {% endblock %}
{% block additional %} <h3> Welcome to Neptune's database of favorite books and authors</h3> {% endblock %}
{% block content %}
<p>My taste in books are very random and usually done in the spur of the moment. I cannot commit to a series. </p>
<div>
<a href="Books/">Books</a>
<a href="Authors/"> Authors</a>
</div>
{% endblock %}
# bookshelf/urls.py
from django.urls import path
from .views import index
from .views import homeView
urlpatterns = [
path('', index, name='index'),
path('home/', homeView, name='home'),
]
# This might be needed, depending on your Django version
......
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
# Create your views here.
from .models import Author, Books
def homeView(request):
return render(request, 'home.html')
class BooksView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetails(DetailView):
model = Books
template_name = 'bookshelf/books_detais.html'
class AuthorView(ListView):
model = Author
template_name = 'bookshelf/author.html'
class AuthorDetails(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
\ No newline at end of file
......@@ -59,7 +59,7 @@ ROOT_URLCONF = 'neptunesy_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......
......@@ -15,7 +15,9 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('' , include('bookshelf.urls', namespace='bookshelf'))
]
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