diff --git a/djangocms_alias/admin.py b/djangocms_alias/admin.py index d605187..4dd3642 100644 --- a/djangocms_alias/admin.py +++ b/djangocms_alias/admin.py @@ -2,7 +2,7 @@ from cms.utils.permissions import get_model_permission_codename from cms.utils.urlutils import admin_reverse from django import forms -from django.contrib import admin +from django.contrib import admin, messages from django.http import ( Http404, HttpRequest, @@ -199,3 +199,13 @@ def has_module_permission(self, request: HttpRequest) -> bool: """Hides admin class in admin site overview""" return False + + def delete_model(self, request: HttpRequest, obj: AliasContent): + if obj.alias._default_manager.filter(language=obj.language).count() == 1: + message = _("Alias content for language {} deleted. A new empty alias content will be created if needed.").format(obj.language) + self.message_user(request, message, level=messages.WARNING) + + return super().delete_model( + request=request, + obj=obj, + ) diff --git a/djangocms_alias/models.py b/djangocms_alias/models.py index 76c20f1..0176218 100644 --- a/djangocms_alias/models.py +++ b/djangocms_alias/models.py @@ -316,11 +316,6 @@ def get_absolute_url(self): def get_template(self): return "djangocms_alias/alias_content.html" - @transaction.atomic - def delete(self, *args, **kwargs): - super().delete(*args, **kwargs) - self.alias.cms_plugins.filter(language=self.language).delete() - @transaction.atomic def populate(self, replaced_placeholder=None, replaced_plugin=None, plugins=None): if not replaced_placeholder and not replaced_plugin: