Display labels for autocomplete fields

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Display labels for autocomplete fields

Ben-302
At present the admin autocomplete docs mention `ModelAdmin.autocomplete_fields` and
`ModelAdmin.search_fields` which are used to configure select2. There are also options for overriding the queryset used.

However there seems to be no way of specifyng what is shown in the autocomplete... it just calls `__str__` on the objects returned.

Would it be possible to add a `search_display_fields` on the relevant ModelAdmin, alongside `search_fields` to customise the display in the form select box? This could be either a model field or a callable on the model or modeladmin.

Cheers!

bjw

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8b785f3f-4158-4a7d-8f9a-41f82995671f%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Display labels for autocomplete fields

Janez Kranjc
I have also come across the need for this and would be willing to work on a pull request for this feature.

On Wednesday, August 7, 2019 at 3:43:43 AM UTC+2, bjw wrote:
At present the admin autocomplete docs mention `ModelAdmin.autocomplete_fields` and
`ModelAdmin.search_fields` which are used to configure select2. There are also options for overriding the queryset used.

However there seems to be no way of specifyng what is shown in the autocomplete... it just calls `__str__` on the objects returned.

Would it be possible to add a `search_display_fields` on the relevant ModelAdmin, alongside `search_fields` to customise the display in the form select box? This could be either a model field or a callable on the model or modeladmin.

Cheers!

bjw

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/2c699014-8362-4ddf-b786-a7fe9d164c2f%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Display labels for autocomplete fields

1337 Shadow Hacker

Would it be possible to add a `search_display_fields` on the relevant ModelAdmin, alongside `search_fields` to customise the display in the form select box? This could be either a model field or a callable on the model or modeladmin.

Another suggestion is to add get_FIELD_autocomplete_display(), to the model or teh ModelAdmin

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/lRaN6wQSqzdeDboF0UO79hAP6jbDoqEXN-xbz32hgU8HRkO4Pvj_bySMpQ7OTO2rB0aNcACTpMF040vUnGEkH74oBgaQDMIyjTG_wDzqeHw%3D%40protonmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Display labels for autocomplete fields

Janez Kranjc
You don't need one for each field. You need one per model - similar to __str__

On Sunday, August 11, 2019 at 3:54:03 PM UTC+2, 1337 Shadow Hacker wrote:

Would it be possible to add a `search_display_fields` on the relevant ModelAdmin, alongside `search_fields` to customise the display in the form select box? This could be either a model field or a callable on the model or modeladmin.

Another suggestion is to add get_FIELD_autocomplete_display(), to the model or teh ModelAdmin

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/30a9993b-2a4c-4996-9fab-3b31eceeb944%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Display labels for autocomplete fields

Ben-302
Actually, I can think of occasions where what is displayed would vary depending on which model the FK was from,  not only on the model that is the target.

bjw

--
You received this message because you are subscribed to the Google Groups "Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/c05cce80-dd59-497e-a6b1-606cfbfa58bf%40googlegroups.com.