feat(api): surface ModelAdmin custom views to the SPA (#439)#539
Merged
Conversation
Many consumers add bespoke admin pages — reports, import/export,
per-object tools — via ModelAdmin.get_urls(). The SPA cannot reach
them. Introspect get_urls(), drop the five standard CRUD routes plus
the unnamed legacy catch-all, and surface every remaining named route
as {name, label, url, level}. Object-level routes (an object_id/pk
capture group) reverse with the object's pk; changelist-level routes
reverse with no args, all through the admin site's namespace.
Detail payload gains object- + changelist-level custom_views; the
registry model entry gains changelist-level ones only. The key is
omitted when empty. Everything is guarded — a misbehaving consumer
get_urls degrades to [] and never 500s. No new permission surface:
this rides the existing detail/registry staff + has_view_permission
gates.
Frontend: DetailPage renders an unobtrusive link-out (a single button,
or a "More" dropdown for several) of real <a target="_blank"> anchors
to the Django-rendered pages. Contract gains a CustomView type.
This is Option A (link-out), the design-safe foundation; the same
payload powers a future iframe/native approach. Reverse only resolves
while the legacy admin remains mounted.
Refs #439
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #439. Revives PR #465 (closed when the human-gate was in force; the user lifted that gate this session). Cherry-picked onto latest
main, re-validated.Custom admin views (
ModelAdmin.get_urls/AdminSite.get_urls) were unreachable in the SPA. This surfaces a registered ModelAdmin's custom URLs on the detail response as a typedcustom_views: [{name, label, url}]list and renders them as link-outs on the detail page — Option A (link-out), conservative and safe (no embedded rendering of an arbitrary admin view).custom_views.pyextracts the admin's custom URL specs (excluding the framework's standard change/history/delete views); detail view returns them; registry helper covers per-admin discovery.test_custom_views.pycovers discovery + the per-object link composition.Per [[feedback-tier-5-6-override]], ship and you review post-merge.
Test plan
tests/test_custom_views.py+test_security.py+test_detail.pygreen (71).pnpm -r typecheck+eslint/dark-mode +ruff+mypyclean.🤖 Generated with Claude Code