diff --git a/books/admin.py b/books/admin.py index 8c38f3f..7bac0d3 100644 --- a/books/admin.py +++ b/books/admin.py @@ -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) \ No newline at end of file diff --git a/books/models.py b/books/models.py index 54dccf1..f9391ce 100644 --- a/books/models.py +++ b/books/models.py @@ -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 \ No newline at end of file + return self.title or self.book.title+' '+str(self.number) \ No newline at end of file diff --git a/books/urls.py b/books/urls.py index 2703166..9e58d50 100644 --- a/books/urls.py +++ b/books/urls.py @@ -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'), -""" \ No newline at end of file + path('',views.book,name='bbook'), + path('/',views.chapter,name='bchap'), +] \ No newline at end of file diff --git a/books/views.py b/books/views.py index 22fb490..ac748c4 100644 --- a/books/views.py +++ b/books/views.py @@ -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+"
You can't actually read books yet, I'm working on it.",'date':'2021/10/24'} \ No newline at end of file + contents='
\n'.join([f'{book} - {book.last_updated}' for book in books]) + return {'title':'Booklist','content':contents+"
\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':'Top
\n'+'
\n'.join([f'{chap} - {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':'

Navigation buttons will come later...

\n'+chapter.contents,'date':chapter.added} \ No newline at end of file diff --git a/rakka/settings.py b/rakka/settings.py index 192b1c3..54f642d 100644 --- a/rakka/settings.py +++ b/rakka/settings.py @@ -80,7 +80,7 @@ WSGI_APPLICATION = 'rakka.wsgi.application' DATABASES = { 'default': { #'ENGINE': 'django.db.backends.sqlite3', - 'ENGINE': 'djongo', + 'ENGINE': conf['DBTYPE'], 'NAME': conf['DBNAME'], } } diff --git a/rakka/urls.py b/rakka/urls.py index b08569f..c477c82 100644 --- a/rakka/urls.py +++ b/rakka/urls.py @@ -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')), ]