Initial implemntation of TOC for books et al.

This commit is contained in:
2025-12-29 12:05:37 +01:00
parent 74d7df2c8b
commit 0880bd0817
4 changed files with 96 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ from bookshelf.models import (
Catalog,
Magazine,
MagazineIssue,
TocEntry,
)
@@ -363,9 +364,23 @@ class CatalogAdmin(SortableAdminBase, admin.ModelAdmin):
actions = [publish, unpublish, download_csv]
class MagazineIssueToc(admin.TabularInline):
model = TocEntry
min_num = 0
extra = 0
fields = (
"title",
"subtitle",
"authors",
"page",
"featured",
)
@admin.register(MagazineIssue)
class MagazineIssueAdmin(SortableAdminBase, admin.ModelAdmin):
inlines = (
MagazineIssueToc,
BookPropertyInline,
BookImageInline,
MagazineIssueDocInline,

View File

@@ -0,0 +1,53 @@
# Generated by Django 6.0 on 2025-12-29 11:02
import django.db.models.deletion
import tinymce.models
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookshelf", "0029_alter_catalog_manufacturer_alter_catalog_scales"),
]
operations = [
migrations.CreateModel(
name="TocEntry",
fields=[
(
"uuid",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("description", tinymce.models.HTMLField(blank=True)),
("notes", tinymce.models.HTMLField(blank=True)),
("creation_time", models.DateTimeField(auto_now_add=True)),
("updated_time", models.DateTimeField(auto_now=True)),
("published", models.BooleanField(default=True)),
("title", models.CharField(max_length=200)),
("subtitle", models.CharField(blank=True, max_length=200)),
("authors", models.CharField(blank=True, max_length=256)),
("page", models.SmallIntegerField()),
("featured", models.BooleanField(default=False)),
(
"book",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="toc",
to="bookshelf.basebook",
),
),
],
options={
"verbose_name": "Table of Contents Entry",
"verbose_name_plural": "Table of Contents Entries",
"ordering": ["page"],
},
),
]

View File

@@ -239,3 +239,30 @@ class MagazineIssue(BaseBook):
return reverse(
"issue", kwargs={"uuid": self.uuid, "magazine": self.magazine.uuid}
)
class TocEntry(BaseModel):
book = models.ForeignKey(
BaseBook, on_delete=models.CASCADE, related_name="toc"
)
title = models.CharField(max_length=200)
subtitle = models.CharField(max_length=200, blank=True)
authors = models.CharField(max_length=256, blank=True)
page = models.SmallIntegerField()
featured = models.BooleanField(
default=False,
)
class Meta:
ordering = ["page"]
verbose_name = "Table of Contents Entry"
verbose_name_plural = "Table of Contents Entries"
def __str__(self):
return f"{self.title} (p. {self.page})"
def clean(self):
if self.page > self.book.number_of_pages:
raise ValidationError(
"Page number exceeds the publication's number of pages."
)

View File

@@ -1,4 +1,4 @@
from ram.utils import git_suffix
__version__ = "0.18.10"
__version__ = "0.19.1"
__version__ += git_suffix(__file__)