8000 feat: admin.Lookup declares a foreign key searched through a bounded staff route by angvp · Pull Request #40 · angvp/tango · GitHub
[go: up one dir, main page]

Skip to content

feat: admin.Lookup declares a foreign key searched through a bounded staff route - #40

Merged
angvp merged 1 commit into
developfrom
feat/admin-fk-lookup
Nov 23, 2026
Merged

angvp merged 1 commit into
developfrom
feat/admin-fk-lookup

Conversation

@angvp
@angvp angvp commented Nov 23, 2026
Copy link
Copy Markdown
Owner

Summary

  • admin.Lookup(LookupOptions{Search}) in Options.Widgets opts one foreign key field into a search.
  • New GET /admin/<model>/_lookup/<Field>/?q= route, staff-gated, Cache-Control: no-store, JSON {items:[{value,text}], more} with only primary key and label.
  • One query per search: page of 10 plus one, contains-LIKE over the search fields plus exact match for an integer primary key, target ordering with the primary key last.
  • Register/install fails with ErrInvalidLookup for a non-FK field, a target not registered with the admin, or missing/non-string search fields.
  • The form is unchanged here: it still renders the select until the combobox lands.

Test plan

  • scripts/check.sh (SQLite)
  • New tests: search, empty page and more, integer key match, label fallback, no-store and value/text only, anonymous redirect, 404/405, startup errors, 500 on failure
  • PostgreSQL and MySQL: a later ticket

…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 i
8000
nteger 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
codecov Bot commented Nov 23, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.39623% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.27%. Comparing base (46270af) to head (9b5a8e8).
⚠️ Report is 1 commits behind head on develop.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
admin/lookup.go 92.78% 7 Missing ⚠️
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     
Flag Coverage Δ
mysql 87.12% <90.56%> (+0.06%) ⬆️
postgres 85.77% <90.56%> (+0.07%) ⬆️
sqlite 93.11% <93.39%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@angvp
angvp merged commit a354e7e into develop Nov 23, 2026
16 of 20 checks passed
@angvp
angvp deleted the feat/admin-fk-lookup branch November 23, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0