Skip to content

Commit 3d8d389

Browse files
committed
Introduce a RefinedModelAdmin class which includes some of the tweaks I want to use elsewhere
1 parent 4b87b3b commit 3d8d389

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Change log
55
Next version
66
============
77

8+
- Introduced ``RefinedModelAdmin`` as a lightweight base class providing common
9+
admin enhancements (currently save shortcuts). The ``ContentEditor`` now
10+
inherits from this base class, and ``RefinedModelAdmin`` can be used
11+
independently for regular model admins that want these tweaks.
12+
813

914
7.3 (2025-06-23)
1015
================

content_editor/admin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ def auto_icon_colors(content_editor):
122122
return content_editor
123123

124124

125-
class ContentEditor(ModelAdmin):
125+
class RefinedModelAdmin(ModelAdmin):
126+
class Media:
127+
js = ["content_editor/save_shortcut.js"]
128+
129+
130+
class ContentEditor(RefinedModelAdmin):
126131
"""
127132
The ``ContentEditor`` is a drop-in replacement for ``ModelAdmin`` with the
128133
speciality of knowing how to work with content editor plugins (that is,
@@ -215,7 +220,6 @@ def _content_editor_media(self, request, context):
215220
},
216221
js=[
217222
"admin/js/jquery.init.js",
218-
"content_editor/save_shortcut.js",
219223
"content_editor/tabbed_fieldsets.js",
220224
JSON(
221225
self._content_editor_context(request, context),

docs/index.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,36 @@ content blocks are Django models, you can do anything you want
544544
inside them.
545545

546546

547+
RefinedModelAdmin
548+
=================
549+
550+
The ``RefinedModelAdmin`` class provides a lightweight base class that extends
551+
Django's ``ModelAdmin`` with commonly useful tweaks. It serves as the foundation
552+
for the ``ContentEditor`` class, but can also be used independently for regular
553+
Django admin classes that want to benefit from these enhancements.
554+
555+
Currently, ``RefinedModelAdmin`` includes:
556+
557+
- **Save shortcuts**: Keyboard shortcuts (Ctrl+S / Cmd+S) for quickly saving forms
558+
- **Deletion safety check**: Shows a confirmation dialog when attempting to delete
559+
the whole object instead of saving changes (including marked inline deletions)
560+
561+
To use ``RefinedModelAdmin`` for your own admin classes:
562+
563+
.. code-block:: python
564+
565+
from content_editor.admin import RefinedModelAdmin
566+
567+
@admin.register(MyModel)
568+
class MyModelAdmin(RefinedModelAdmin):
569+
# Your admin configuration here
570+
pass
571+
572+
This gives you the save shortcut functionality without the full content editor
573+
interface, making it useful for any Django model admin where you want these
574+
convenience features.
575+
576+
547577
Glossary
548578
========
549579

0 commit comments

Comments
 (0)