From f920788bf885288af11960684b888a60c3ec09dc Mon Sep 17 00:00:00 2001 From: Will Barton Date: Tue, 17 Sep 2024 13:29:33 -0400 Subject: [PATCH] Make footnotes orderable Rather than a potentially random order, that changes from initial draft after save, allow a content editor to change the ordering of footnotes in the editor by making them inherit from `wagtail.models.Orderable`. --- ...er_footnote_options_footnote_sort_order.py | 21 +++++++++++++++++++ wagtail_footnotes/models.py | 7 +++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 wagtail_footnotes/migrations/0007_alter_footnote_options_footnote_sort_order.py diff --git a/wagtail_footnotes/migrations/0007_alter_footnote_options_footnote_sort_order.py b/wagtail_footnotes/migrations/0007_alter_footnote_options_footnote_sort_order.py new file mode 100644 index 0000000..615e9ff --- /dev/null +++ b/wagtail_footnotes/migrations/0007_alter_footnote_options_footnote_sort_order.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.15 on 2024-09-17 17:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("wagtail_footnotes", "0006_alter_footnote_locale"), + ] + + operations = [ + migrations.AlterModelOptions( + name="footnote", + options={"ordering": ["sort_order"]}, + ), + migrations.AddField( + model_name="footnote", + name="sort_order", + field=models.IntegerField(blank=True, editable=False, null=True), + ), + ] diff --git a/wagtail_footnotes/models.py b/wagtail_footnotes/models.py index 353da48..a7a515b 100644 --- a/wagtail_footnotes/models.py +++ b/wagtail_footnotes/models.py @@ -1,16 +1,15 @@ from django.conf import settings -from django.db import models from django.utils.translation import gettext_lazy as _ from modelcluster.fields import ParentalKey from wagtail.admin.panels import FieldPanel from wagtail.fields import RichTextField -from wagtail.models import TranslatableMixin +from wagtail.models import Orderable, TranslatableMixin from wagtail_footnotes.fields import CustomUUIDField from wagtail_footnotes.widgets import ReadonlyUUIDInput -class Footnote(TranslatableMixin, models.Model): +class Footnote(TranslatableMixin, Orderable): """ Footnote has a UUID field which is set using JavaScript on object creation so that it is available immediately for hardcoding a reference to the @@ -32,7 +31,7 @@ class Footnote(TranslatableMixin, models.Model): panels = [FieldPanel("text"), FieldPanel("uuid", widget=ReadonlyUUIDInput)] - class Meta(TranslatableMixin.Meta): + class Meta(TranslatableMixin.Meta, Orderable.Meta): unique_together = [("page", "uuid"), ("translation_key", "locale")] def __str__(self):