Basic book reading should now be possible.
This commit is contained in:
parent
a0dbdf0a4a
commit
a3d144fbc0
|
@ -1,3 +1,7 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
from .models import Book,Chapter
|
||||||
|
admin.site.register(Book)
|
||||||
|
admin.site.register(Chapter)
|
|
@ -4,7 +4,9 @@ from datetime import date
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
title=models.CharField(max_length=200)
|
title=models.CharField(max_length=200)
|
||||||
|
url=models.CharField(max_length=100)
|
||||||
added=models.DateField(auto_now_add=True)
|
added=models.DateField(auto_now_add=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_updated(self):
|
def last_updated(self):
|
||||||
return Chapter.objects.filter(book=self).order_by('added')[0].added
|
return Chapter.objects.filter(book=self).order_by('added')[0].added
|
||||||
|
@ -15,9 +17,9 @@ class Book(models.Model):
|
||||||
class Chapter(models.Model):
|
class Chapter(models.Model):
|
||||||
book=models.ForeignKey(Book, on_delete=models.CASCADE)
|
book=models.ForeignKey(Book, on_delete=models.CASCADE)
|
||||||
number=models.IntegerField(default=0)
|
number=models.IntegerField(default=0)
|
||||||
title=models.CharField(max_length=200)
|
title=models.CharField(max_length=200, blank=True, null=True)
|
||||||
contents=models.TextField()
|
contents=models.TextField(blank=True, null=True)
|
||||||
added=models.DateField(auto_now_add=True)
|
added=models.DateField(auto_now_add=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title or self.book.title+' '+self.number
|
return self.title or self.book.title+' '+str(self.number)
|
|
@ -3,17 +3,6 @@ from . import views
|
||||||
|
|
||||||
urlpatterns=[
|
urlpatterns=[
|
||||||
path('',views.index,name='bidex'),
|
path('',views.index,name='bidex'),
|
||||||
]
|
path('<str:bookurl>',views.book,name='bbook'),
|
||||||
|
path('<str:bookurl>/<int:chapnum>',views.chapter,name='bchap'),
|
||||||
"""
|
]
|
||||||
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'),
|
|
||||||
"""
|
|
|
@ -46,5 +46,17 @@ def parsecat(file,n):
|
||||||
def index():
|
def index():
|
||||||
books=models.Book.objects.all()
|
books=models.Book.objects.all()
|
||||||
#Make table I guess, for now just get data up there
|
#Make table I guess, for now just get data up there
|
||||||
contents='\n'.join([f'{book.title} - {book.last_updated}' for book in books])
|
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/>You can't actually read books yet, I'm working on it.",'date':'2021/10/24'}
|
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}
|
|
@ -80,7 +80,7 @@ WSGI_APPLICATION = 'rakka.wsgi.application'
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
#'ENGINE': 'django.db.backends.sqlite3',
|
#'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'ENGINE': 'djongo',
|
'ENGINE': conf['DBTYPE'],
|
||||||
'NAME': conf['DBNAME'],
|
'NAME': conf['DBNAME'],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ from django.urls import include, path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('books/',include('books.urls')),
|
path('books/',include('books.urls')),
|
||||||
path('', include('main.urls')),
|
path('', include('main.urls')),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user