Private
Public Access
Make the Site settings admin page go straight to the edit form
It's a true singleton, not a collection, so the normal changelist (an "Add" link, a list with 0 or 1 rows, an extra click to get to the one row) was just friction — and visually inconsistent with every other app's admin section, which do show an "Add" link. The changelist view now redirects straight to the single row's change form (creating it first if this is a fresh install), and "Add" is never offered at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc8b9ff83b
commit
90837b339c
2 files changed
+32
-12
No files matched your search
+15
-5
@@ -1,18 +1,28 @@
|
||||
from django.contrib import admin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import SiteSettings
|
||||
|
||||
|
||||
@admin.register(SiteSettings)
|
||||
class SiteSettingsAdmin(admin.ModelAdmin):
|
||||
list_display = ["fetch_interval_minutes"]
|
||||
"""A true singleton, not a collection — browsing a changelist to pick
|
||||
the one row and click into it is an extra, pointless step, so
|
||||
"Core > Site settings" in the sidebar goes straight to the (only)
|
||||
change form instead, creating the row first if this is a fresh
|
||||
install. No changelist/add/delete views exist at all here.
|
||||
"""
|
||||
|
||||
fields = ["fetch_interval_minutes"]
|
||||
|
||||
def has_add_permission(self, request):
|
||||
# Singleton — only offer "Add" when the row doesn't exist yet
|
||||
# (a fresh install before the first poll_due_feeds run or admin
|
||||
# visit has created it via SiteSettings.load()).
|
||||
return not SiteSettings.objects.exists()
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
settings_row = SiteSettings.load()
|
||||
url = reverse("admin:core_sitesettings_change", args=[settings_row.pk])
|
||||
return redirect(url)
|
||||
Reference in new issue
Block a user