Skip to content

V0.1#12

Merged
ayahaustine merged 2 commits intomainfrom
v0.1
Mar 9, 2026
Merged

V0.1#12
ayahaustine merged 2 commits intomainfrom
v0.1

Conversation

@ayahaustine
Copy link
Copy Markdown
Owner

@ayahaustine ayahaustine commented Mar 9, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced foreign key field handling with intelligent label discovery and optimized choice queries.
  • Bug Fixes

    • Improved type coercion for filter values across multiple data types.
    • Fixed select field rendering when option and form values have different types.

@ayahaustine ayahaustine merged commit b6bcaf5 into main Mar 9, 2026
0 of 10 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb64a9e6-24ce-4617-80cb-f253136e8b47

📥 Commits

Reviewing files that changed from the base of the PR and between 1df8e88 and a41bfa1.

📒 Files selected for processing (6)
  • internal_admin/admin/filters.py
  • internal_admin/admin/form_engine.py
  • internal_admin/admin/query_engine.py
  • internal_admin/templates/admin/form.html
  • tests/conftest.py
  • tests/test_admin.py

📝 Walkthrough

Walkthrough

The changes implement robust foreign key handling across the admin interface by adding relationship introspection, type-aware value coercion, and improved choice discovery logic in filters, form engine, and query engine layers, alongside template fixes and comprehensive test coverage.

Changes

Cohort / File(s) Summary
Foreign Key Filter & Form Engine
internal_admin/admin/filters.py, internal_admin/admin/form_engine.py
Enhanced foreign key resolution with relationship introspection, dynamic choice discovery from related models, display label attribute selection (display_name, name, title, username, email), and result limiting to 200 items. Adds fallback mechanisms for missing related data.
Query Engine Type Coercion
internal_admin/admin/query_engine.py
Introduces _coerce_filter_value() helper for type-aware value coercion. Handles SQLAlchemy type derivation (including TypeDecorator), converts values to Boolean, Integer, Float, Date, or DateTime, and integrates coercion into filter application logic.
Template Selection Fix
internal_admin/templates/admin/form.html
Updates option selection comparison to coerce both current form value and option value to strings before equality check, resolving type mismatch issues in select fields.
Test Infrastructure
tests/conftest.py, tests/test_admin.py
Adds TestCategory and TestProduct models with foreign key relationship, related admin configurations, and new test class TestForeignKeys with three tests covering FK choice rendering, relation persistence, and FK-based filtering.

Sequence Diagram

sequenceDiagram
    participant User
    participant FormEngine
    participant Database
    participant Filter
    participant QueryEngine
    participant Template

    User->>FormEngine: Request form with FK field
    FormEngine->>FormEngine: _find_related_model()
    FormEngine->>Database: Query related model instances (limit 200)
    Database-->>FormEngine: Related model rows
    FormEngine->>FormEngine: _resolve_label_attribute()
    FormEngine->>FormEngine: Build (value, display) pairs
    FormEngine->>Template: Render select with choices
    Template-->>User: Display form with FK options

    User->>User: Select FK value and submit
    User->>FormEngine: Form data with FK value
    FormEngine->>Filter: FK value for filtering
    Filter->>Filter: _find_relationship()
    Filter->>Filter: _coerce_filter_value() - type conversion
    Filter->>QueryEngine: Apply filter with coerced value
    QueryEngine->>QueryEngine: _coerce_filter_value() - validate type
    QueryEngine->>Database: Execute filtered query
    Database-->>QueryEngine: Filtered results
    QueryEngine-->>User: Return matching records
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whiskers twitch with foreign key delight,
Relations discovered in the database night,
Types coerce to integers, dates align,
Select options sparkle, choices divine!
From form to filter, the logic flows true,
A rabbit's work here—efficient and new! 🥕

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v0.1

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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