#29010: Allow customizing the autocomplete search results based on the querying model -------------------------------------+------------------------------------- Reporter: Muslu Y. | Owner: Johannes | Hoppe Type: Bug | Status: assigned Component: contrib.admin | Version: 2.0 Severity: Normal | Resolution: Keywords: ForeignKey, | Triage Stage: Accepted get_search_results, search_fields | Has patch: 1 | Needs documentation: 1 Needs tests: 1 | Patch needs improvement: 1 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Gordon Wrigley): It would be really nice if it were easy to inject additional values into the widget at form construction time and then filter on them in get_search_results. With the current patch I believe that would require: 1: overriding build_attrs to pass the value along 2: overriding autocomplete.js to pass the value along Regarding these: 1: is not a particularly big deal, but could be tidied up with something like a get_search_args. 2: this is annoying just because it's outside the python, it would be nice if it was a wild card pass, perhaps the fields could be bundled into a dict or some such. After than you can pull the values off the request in get_search_results, which is maybe not elegant, but works fine. In terms or what values to pass along the most useful and the ones on my mind are the model and pk of the admin page the autocomplete is resident on. The page specifically because when there's dynamic (can add and remove) inlines involved the model and pk of the inlined object is not always useful. As an example if you consider polls and choices this is required for a "default_choice" field which is only allowed to choose from the polls existing choices. -- Ticket URL: <https://code.djangoproject.com/ticket/29010#comment:27> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/071.e50dbc37b8b952b3210e808d0af09698%40djangoproject.com.