Finalized and updated to implement the web pages

parent 27be1865
......@@ -60,7 +60,7 @@ ROOT_URLCONF = 'addysalto_reading.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -122,6 +122,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/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', namespace="bookshelf")),
path('', include('bookshelf.urls', namespace="bookshelf")),
path('admin/', admin.site.urls),
]
......@@ -4,10 +4,16 @@ from .models import Author, Books
class AuthorAdmin(admin.ModelAdmin):
model = Author
model = Author
search_fields = ('first_name', 'last_name')
list_display = ('first_name', 'last_name', 'age', 'nationality', 'bio')
class BooksAdmin(admin.ModelAdmin):
model = Books
model = Books
search_fields = ('title', 'author')
list_display = ('title', 'author', 'publisher', 'year_published', 'ISBN', 'blurb')
admin.site.register(Author, AuthorAdmin)
......
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from django.urls import reverse
import datetime
class Author(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
age = models.PositiveSmallIntegerField()
nationality = models.CharField(max_length=100)
bio = models.TextField(max_length=700)
first_name = models.CharField(max_length=100, default='')
last_name = models.CharField(max_length=100, default='')
age = models.PositiveSmallIntegerField(default='0')
nationality = models.CharField(max_length=100, default='')
bio = models.TextField(max_length=700, default='')
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:authors-detail', kwargs={'pk': self.pk})
class Books(models.Model):
title = models.CharField(max_length=255)
title = models.CharField(max_length=255, default='')
author = models.ForeignKey(Author, on_delete=models.CASCADE)
publisher = models.CharField(max_length=100)
year_published =
ISBN = models.IntegerField(max_length=13)
blurb = models.TextField()
\ No newline at end of file
publisher = models.CharField(max_length=100, default='')
YEAR_PUBLISHED_CHOICES = [(r,r) for r in range(1454, datetime.date.today().year+1)]
year_published = models.PositiveIntegerField(choices=YEAR_PUBLISHED_CHOICES,
default=datetime.datetime.today().year)
ISBN = models.PositiveIntegerField(
validators=[MaxValueValidator(9999999999999),
MinValueValidator(0000000000000)],
default=1000000000000)
blurb = models.TextField(default='')
def __str__(self):
return '{} by {}, {}'.format(self.title, self.author, self.year_published)
def get_absolute_url(self):
return reverse('bookshelf:books-detail', kwargs={'pk': self.pk})
\ No newline at end of file
from django.urls import path
from .views import index
from .views import index, homepage, BookListView, BookDetailView, AuthorListView, AuthorDetailView
urlpatterns = [
path('', index, name='index'),
path('home', homepage, name='home'),
path('books', BookListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='books-detail'),
path('authors', AuthorListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='authors-detail'),
]
app_name = "bookshelf"
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 Books, Author
def index(request):
return HttpResponse('Hello World! This came from the index view')
\ No newline at end of file
return HttpResponse('')
def homepage(request):
return render(request, 'bookshelf/home.html')
class BookListView(ListView):
model = Books
template_name = 'bookshelf/books.html'
class BookDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
class AuthorListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
def get_context_data(self,**kwargs):
context = super ().get_context_data (**kwargs)
context['books'] = Books.objects.all()
return context
\ 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