Basic book reading should now be possible.

This commit is contained in:
Zergling_man 2021-10-27 19:09:18 +11:00
parent a0dbdf0a4a
commit a3d144fbc0
6 changed files with 28 additions and 21 deletions

View File

@ -1,3 +1,7 @@
from django.contrib import admin
# Register your models here.
from .models import Book,Chapter
admin.site.register(Book)
admin.site.register(Chapter)

View File

@ -4,7 +4,9 @@ from datetime import date
# Create your models here.
class Book(models.Model):
title=models.CharField(max_length=200)
url=models.CharField(max_length=100)
added=models.DateField(auto_now_add=True)
@property
def last_updated(self):
return Chapter.objects.filter(book=self).order_by('added')[0].added
@ -15,9 +17,9 @@ class Book(models.Model):
class Chapter(models.Model):
book=models.ForeignKey(Book, on_delete=models.CASCADE)
number=models.IntegerField(default=0)
title=models.CharField(max_length=200)
contents=models.TextField()
title=models.CharField(max_length=200, blank=True, null=True)
contents=models.TextField(blank=True, null=True)
added=models.DateField(auto_now_add=True)
def __str__(self):
return self.title or self.book.title+' '+self.number
return self.title or self.book.title+' '+str(self.number)

View File

@ -3,17 +3,6 @@ from . import views
urlpatterns=[
path('',views.index,name='bidex'),
]
"""
path('books/',include('books.urls')),
path('contact',views.contact,name='contact'),
path('specs',views.specs,name='specs'),
path('songs',views.songs,name='songs'),
path('nerdshope',views.nerdshope,name='shop'),
path('teapot',views.teapot,name='teapot'),
path('toask',views.articles,name='articles'),
re_path('r/(.*)',views.redirect,name='redirect'),
path('md.rss',views.md,name='md'),
re_path('(.*)',views.autopage,name='everything'),
"""
path('<str:bookurl>',views.book,name='bbook'),
path('<str:bookurl>/<int:chapnum>',views.chapter,name='bchap'),
]

View File

@ -46,5 +46,17 @@ def parsecat(file,n):
def index():
books=models.Book.objects.all()
#Make table I guess, for now just get data up there
contents='\n'.join([f'{book.title} - {book.last_updated}' for book in books])
return {'title':'Booklist','content':contents+"<br/>You can't actually read books yet, I'm working on it.",'date':'2021/10/24'}
contents='<br/>\n'.join([f'<a href="/books/{book.url}">{book}</a> - {book.last_updated}' for book in books])
return {'title':'Booklist','content':contents+"<br/>\nYou should be able to read books now.",'date':'2021/10/24'}
@rerender
def book(bookurl):
book=models.Book.objects.filter(url=bookurl)[0]
chapters=models.Chapter.objects.filter(book=book).order_by('added')
return {'title':book.title,'content':'<a href="/books/">Top</a><br/>\n'+'<br/>\n'.join([f'<a href="/books/{book.url}/{chap.number}">{chap}</a> - {chap.added}' for chap in chapters]),'date':book.last_updated}
@rerender
def chapter(bookurl,chapnum):
book=models.Book.objects.filter(url=bookurl)[0]
chapter=models.Chapter.objects.filter(book=book,number=chapnum)[0]
return {'title':chapter,'content':'<p>Navigation buttons will come later...</p>\n'+chapter.contents,'date':chapter.added}

View File

@ -80,7 +80,7 @@ WSGI_APPLICATION = 'rakka.wsgi.application'
DATABASES = {
'default': {
#'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'djongo',
'ENGINE': conf['DBTYPE'],
'NAME': conf['DBNAME'],
}
}

View File

@ -18,7 +18,7 @@ from django.urls import include, path
from . import views
urlpatterns = [
path('admin', admin.site.urls),
path('admin/', admin.site.urls),
path('books/',include('books.urls')),
path('', include('main.urls')),
]