Premier League Predictor: Django & MySQL — Chapter 3, Exercise 1 ==================================================== TASK Explain why autocomplete_fields = ('team',) on SeasonTeamInline requires TeamAdmin to define search_fields, and what would happen if TeamAdmin's search_fields were removed. SOLUTION autocomplete_fields doesn't implement its own search logic — it works by turning the field into a Select2-powered widget that makes real AJAX requests back to the target model's own admin search endpoint as the user types, and reuses whatever search behavior that model's admin already provides on its own list page. The search endpoint Django exposes for this is built directly from the target model's own ModelAdmin.search_fields — the exact same setting that powers the search box on TeamAdmin's regular list page. Because autocomplete_fields depends on that endpoint existing and knowing which fields to search, TeamAdmin needs search_fields defined specifically so there's a real search behavior for the autocomplete widget to call into. Without it, there's nothing for the widget to ask Team to search by. If TeamAdmin's search_fields were removed, Django raises a real, explicit configuration error the moment the admin app starts (a system check failure) rather than silently falling back to a plain dropdown — Django's own documentation requires any model referenced by autocomplete_fields elsewhere to have search_fields defined on its own admin, and enforces this as a hard requirement, not an optional nicety. WHY THIS WORKS AS AN ANSWER ---------------------------- It explains the real mechanism autocomplete_fields relies on (an AJAX search endpoint built from the target model's own search_fields), why that creates a genuine dependency between SeasonTeamInline and TeamAdmin, and correctly identifies that removing search_fields produces a real, hard configuration error rather than a silent fallback.