diff --git a/docs/reference/pages/model_reference.rst b/docs/reference/pages/model_reference.rst index d00ae841d9..f5a2dd84fd 100644 --- a/docs/reference/pages/model_reference.rst +++ b/docs/reference/pages/model_reference.rst @@ -123,6 +123,12 @@ Database fields The date/time when the page was locked. + .. attribute:: alias_of + + (foreign key to another page) + + If set, this page is an alias of the page referenced in this field. + Methods and properties ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/wagtail/core/migrations/0058_page_alias_of.py b/wagtail/core/migrations/0058_page_alias_of.py new file mode 100644 index 0000000000..2e1cacc658 --- /dev/null +++ b/wagtail/core/migrations/0058_page_alias_of.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.9 on 2020-08-04 12:38 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0057_page_locale_fields_notnull'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='alias_of', + field=models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='aliases', to='wagtailcore.Page'), + ), + ] diff --git a/wagtail/core/models.py b/wagtail/core/models.py index c5f581b3a2..5e6408a74f 100644 --- a/wagtail/core/models.py +++ b/wagtail/core/models.py @@ -760,6 +760,18 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): editable=False ) + # If non-null, this page is an alias of the linked page + # This means the page is kept in sync with the live version + # of the linked pages and is not editable by users. + alias_of = models.ForeignKey( + 'self', + on_delete=models.SET_NULL, + null=True, + blank=True, + editable=False, + related_name='aliases', + ) + search_fields = [ index.SearchField('title', partial_match=True, boost=2), index.AutocompleteField('title'), @@ -2255,11 +2267,13 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): * ``locked_at`` * ``latest_revision_created_at`` * ``first_published_at`` + * ``alias_of`` """ obj = self.specific_class.from_json(content_json) # These should definitely never change between revisions + obj.id = self.id obj.pk = self.pk obj.content_type = self.content_type @@ -2285,6 +2299,7 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase): obj.first_published_at = self.first_published_at obj.translation_key = self.translation_key obj.locale = self.locale + obj.alias_of_id = self.alias_of_id return obj