Repository navigation
feat: admin.Lookup declares a foreign key searched through a bounded staff route - #40
Merged
Merged
Conversation
…staff route A foreign key field can be declared with admin.Lookup in Options.Widgets. The admin then serves GET /admin/<model>/_lookup/<Field>/?q= behind the staff gate with Cache-Control: no-store, answering JSON with only the primary key and label of up to ten rows, plus whether more exist. One query per search: contains-LIKE over the search fields and exact match on an intege 8000 r primary key, in the target's ordering with the primary key last. Registration fails at startup with ErrInvalidLookup when the field is not a foreign key, its target is not registered with the admin, or no usable search fields exist. The form still renders the select until the lookup control lands.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #40 +/- ##
===========================================
- Coverage 94.27% 94.27% -0.01%
===========================================
Files 234 235 +1
Lines 13682 13786 +104
===========================================
+ Hits 12899 12997 +98
- Misses 783 789 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
admin.Lookup(LookupOptions{Search})inOptions.Widgetsopts one foreign key field into a search.GET /admin/<model>/_lookup/<Field>/?q=route, staff-gated,Cache-Control: no-store, JSON{items:[{value,text}], more}with only primary key and label.LIKEover the search fields plus exact match for an integer primary key, target ordering with the primary key last.Register/install fails withErrInvalidLookupfor a non-FK field, a target not registered with the admin, or missing/non-string search fields.Test plan
scripts/check.sh(SQLite)more, integer key match, label fallback, no-store and value/text only, anonymous redirect, 404/405, startup errors, 500 on failure