From 445d26a88cd6a65703df14084df414aafbcb0d91 Mon Sep 17 00:00:00 2001 From: Conor Holden Date: Wed, 6 Nov 2024 19:49:14 +0100 Subject: [PATCH] :construction: create migrations for CMS 4 --- djangocms_page_meta/admin.py | 7 +++++-- .../migrations/0017_auto_20241106_1740.py | 20 +++++++++++++++++++ djangocms_page_meta/models.py | 15 ++++++++++---- 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 djangocms_page_meta/migrations/0017_auto_20241106_1740.py diff --git a/djangocms_page_meta/admin.py b/djangocms_page_meta/admin.py index 8b7a3f8..d75da51 100644 --- a/djangocms_page_meta/admin.py +++ b/djangocms_page_meta/admin.py @@ -1,5 +1,8 @@ from cms.admin.pageadmin import PageAdmin -from cms.extensions import PageExtensionAdmin, TitleExtensionAdmin +try: + from cms.extensions import PageExtensionAdmin, PageContentExtensionAdmin +except ImportError: + from cms.extensions import PageExtensionAdmin, TitleExtensionAdmin as PageContentExtensionAdmin from cms.utils import get_language_from_request from django.conf import settings from django.contrib import admin @@ -68,7 +71,7 @@ def get_model_perms(self, request): @admin.register(TitleMeta) -class TitleMetaAdmin(TitleExtensionAdmin): +class TitleMetaAdmin(PageContentExtensionAdmin): form = TitleMetaAdminForm inlines = (GenericAttributeTitleInline,) diff --git a/djangocms_page_meta/migrations/0017_auto_20241106_1740.py b/djangocms_page_meta/migrations/0017_auto_20241106_1740.py new file mode 100644 index 0000000..8d0642f --- /dev/null +++ b/djangocms_page_meta/migrations/0017_auto_20241106_1740.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.25 on 2024-11-06 16:40 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangocms_page_meta', '0016_auto_20230830_1007'), + ('cms', '0032_remove_title_to_pagecontent'), + ] + + operations = [ + migrations.AlterField( + model_name="titlemeta", + name="extended_object", + field=models.OneToOneField(editable=False, on_delete=django.db.models.deletion.CASCADE, to="cms.PageContent"), + ), + ] diff --git a/djangocms_page_meta/models.py b/djangocms_page_meta/models.py index 0b6f6e5..f7e916c 100644 --- a/djangocms_page_meta/models.py +++ b/djangocms_page_meta/models.py @@ -1,8 +1,15 @@ import ast -from cms.extensions import PageExtension, TitleExtension +try: + from cms.models import Page, PageContent + from cms.extensions import PageExtension, PageContentExtension +except ImportError: + from cms.extensions import PageExtension, TitleExtension as PageContentExtension + from cms.models import Page, Title as PageContent + + from cms.extensions.extension_pool import extension_pool -from cms.models import Page, Title + from django.conf import settings from django.core.cache import cache from django.db import models @@ -98,7 +105,7 @@ def robots_list(self): extension_pool.register(PageMeta) -class TitleMeta(TitleExtension): +class TitleMeta(PageContentExtension): image = FilerFileField( null=True, blank=True, @@ -206,7 +213,7 @@ def cleanup_page(sender, instance, **kwargs): cache.delete(key) -@receiver(pre_delete, sender=Title) +@receiver(pre_delete, sender=PageContent) def cleanup_title(sender, instance, **kwargs): key = get_cache_key(instance.page, instance.language) cache.delete(key)