Package: django-dynamic-raw-id
django-dynamic-raw-idA Django admin raw_id_fields widget replacement that handles display of an
object’s string value on change and can be overridden via a template.
See this example:Compatibility Matrix:Py/Dj3.73.83.93.103.2✓✓✓✓4.0✓✓✓✓InstallationInstall the package withpip:$pipinstalldjango-dynamic-raw-idPutdynamic_raw_idto your list ofINSTALLED_APPS:INSTALLED_APPS=(# ... other apps'dynamic_raw_id',)And add theurlpattern. Make sure its listedbeforethe genericadmin.site.urlsurlpattern include:urlpatterns=[# ...path('admin/dynamic_raw_id/',include('dynamic_raw_id.urls')),path("admin/",admin.site.urls),]dynamic_raw_idcomes with some static files so don’t forget to runmanage.py collectstatic.UsageTo start using django-dynamic-raw-id in your application all you need to do is
implementDynamicRawIDMixinin yourModelAdminclass and add the desired
fields to a list ofdynamic_raw_id_fields:fromdynamic_raw_id.adminimportDynamicRawIDMixinclassUserProfileAdmin(DynamicRawIDMixin,admin.ModelAdmin):dynamic_raw_id_fields=('user',)You can use dynamic_raw_id widgets in a Admin filter as well:fromdynamic_raw_id.adminimportDynamicRawIDMixinfromdynamic_raw_id.filtersimportDynamicRawIDFilterclassUserProfileAdmin(DynamicRawIDMixin,admin.ModelAdmin):list_filter=(('dynamic_raw_id_fk',DynamicRawIDFilter),)Customizing the value of the dynamic widgetThe coolest feature of django-dynamic-raw-id is the ability to customize the output
of the value displayed alongside theDynamicRawIDWidget.  There is a basic
implementation if all you want is your object’s__unicode__value. To change
the value displayed all you need to do is implement the correct template.django-dynamic-raw-id looks for this template structuredynamic_raw_id/<app>/<model>.htmlanddynamic_raw_id/<app>/multi_<model>.html(for multi-value lookups).For instance, if I have a blog post with aUserdynamic_raw_id field that I want
display asFirstname Lastname, I would create the templatedynamic_raw_id/auth/user.htmlwith:<span>{{object.0.first_name}}{{object.0.last_name}}</span>A custom admin URL prefixIf you have your adminandthe dynamic_raw_id scripts located on a different
prefix than/admin/dynamic_raw_id/you need adjust theDYNAMIC_RAW_ID_MOUNT_URLJS variable.Example:# In case the app is setup at /foobar/dynamic_raw_id/
url(r'^foobar/dynamic_raw_id/', include('dynamic_raw_id.urls')),

# Provide a
<script>
    window.DYNAMIC_RAW_ID_MOUNT_URL = "{% url "admin:index" %}";
</script>An ideal place is the adminbase_site.htmltemplate. Full example:{%extends"admin/base.html"%}{%blocktitle%}{{title}}|{{site_title|default:_('Django site admin')}}{%endblock%}{%blockextrahead%}{{block.super}}<script>window.DYNAMIC_RAW_ID_MOUNT_URL="{%url"admin:index"%}";</script>{%endblock%}{%blockbranding%}<h1id="site-name"><ahref="{%url'admin:index'%}">{{site_header|default:_('Django administration')}}</a></h1>{%endblock%}{%blocknav-global%}{%endblock%}Testing and Local DevelopmentThe testsuite uses Selenium to do frontend tests, we require Firefox andgeckodriverto be installed. You can install geckodriver on OS X with
Homebrew:$brewinstallgeckodriverRun the testsuite in your local environment using:$cddjango-dynamic-raw-id/$pipenvinstall--dev$pipenvrunpytestOr use tox to test against various Django and Python versions:$tox-rYou can also invoke the test suite or other ‘manage.py’ commands by calling
thedjango-admintool with the test app settings:$cddjango-dynamic-raw-id/$pipenvinstall--dev$pipenvrunpytestThis also allows you to run the internal testing app in a testserver, to
preview a sample of what django-dynamic-raw-id is doing:$pipenvrundjango-adminmigrate$pipenvrundjango-admincreatesuperuser$pipenvrundjango-adminrunserverNoteThe default settings file is set in the.envfile which
pipenv automatically exposes:DJANGO_SETTINGS_MODULE=dynamic_raw_id.tests.testapp.settingsChangelogv3.0 (2022-03-20)Django 4.0 compatibility and tests.Requires Django 3.2 or up.Requires Python 3.7 or up.Note:You may now need to change the order and put the dynamic-raw-id
include before the generic admin include. See Readme for details.v2.8 (2020-12-02)Django 3.1 compatibility and tests.v2.7 (2020-05-02)Django 3.0 compatibility and tests.v2.6 (2019-06-21)BACKWARDS INCOMPATIBLE: Dropped support for Django <1.11.BACKWARDS INCOMPATIBLE: Dropped support for Python 3.4.Django 2.2 compatibility and tests.General code cleanup.Pipenv support for local development.Some visual fixes around icons and alignment.v2.5 (2018-12-09)Django 2.1 compatibility and tests.v2.4 (2018-04-09)Fixes missing icons in Admin views.Fixes missing JS handling when using a custom /admin/ url.v2.3 (2018-01-18)BACKWARDS INCOMPATIBLE: Renamed the project todjango-dynamic-raw-id.
to reflect what it’s  actually doing.Fixed glass lookup icon in Django 1.10 and below.Specific ordering of media asset loading.v1.2 (2018-01-17)Multiple fixes and enhancements.Full Selenium based testsuite.Django 2.0 and Python 3 compatibility.pipenv support.