Skip to content

Commit f0685d3

Browse files
author
Cameron Lamb
authored
Footnote make Page and UUID unique together (#16)
* Make Footnotes unique on page-uuid * Add migration * Fix migration and Footnote.DoesNotExist exception * Footnote.DoesNotExist is no longer needed We no longer run .get(), instead we store a list of the page's footnotes, we will get a KeyError if there is an invalid footnote reference.
1 parent 6e52cc8 commit f0685d3

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Clean up old step from README - It is no longer recommended to define footnotes in `WAGTAILADMIN_RICH_TEXT_EDITORS`
66
- Add `footnotes` rich text feature automatically
77
- Clean up `RichTextBlockWithFootnotes`
8+
- Make Footnotes unique on `page` <-> `uuid`
89

910
## 0.6.0
1011

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 3.2.4 on 2021-06-24 10:18
2+
3+
from django.db import migrations
4+
import wagtail_footnotes.fields
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("wagtailcore", "0041_group_collection_permissions_verbose_name_plural"),
11+
("wagtail_footnotes", "0001_initial"),
12+
]
13+
14+
operations = [
15+
migrations.AlterUniqueTogether(
16+
name="footnote",
17+
unique_together={("page", "uuid")},
18+
),
19+
migrations.AlterField(
20+
model_name="footnote",
21+
name="uuid",
22+
field=wagtail_footnotes.fields.CustomUUIDField(
23+
help_text="The ID of the footnote is shown in the rich text editor for reference.",
24+
verbose_name="ID",
25+
),
26+
),
27+
]

wagtail_footnotes/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class Footnote(models.Model):
1717

1818
page = ParentalKey("wagtailcore.Page", related_name="footnotes")
1919
uuid = CustomUUIDField(
20-
unique=True,
2120
verbose_name="ID",
2221
help_text="The ID of the footnote is shown in the rich text editor for "
2322
"reference.",
2423
)
2524
text = RichTextField(
2625
features=getattr(
27-
settings,
28-
'WAGTAIL_FOOTNOTES_TEXT_FEATURES',
29-
["bold", "italic", "link"]
26+
settings, "WAGTAIL_FOOTNOTES_TEXT_FEATURES", ["bold", "italic", "link"]
3027
)
3128
)
3229

3330
panels = [FieldPanel("text"), FieldPanel("uuid", widget=ReadonlyUUIDInput)]
31+
32+
class Meta:
33+
unique_together = ("page", "uuid")

0 commit comments

Comments
 (0)