34
If you are using Django >= 2.0, you can take advantage of a feature called autocomplete_fields
. You must define search_fields
on the related object’s ModelAdmin because the autocomplete search uses it.
Since you have a ForeignKey
relationship to Asset
in WorkOrder
, in the admin.py
of your app add the following:
from django.contrib import admin
@admin.register(Asset)
class AssetAdmin(admin.ModelAdmin):
search_fields = ["serial_number", "asset_tag"]
@admin.register(WorkOrder)
class WorkOrderAdmin(admin.ModelAdmin):
autocomplete_fields = ["asset"]
Add the fields you want to use for searching to search_fields
, and add define autocomplete_fields
as shown in the code above.
- [Django]-Turn off automatic pagination of Django Rest Framework ModelViewSet
- [Django]-Count number of records by date in Django
- [Django]-How do I get odd and even values in a Django for loop template?
- [Django]-XML Unicode strings with encoding declaration are not supported
- [Django]-Optional fields in django models
- [Django]-Django "Remember Me" with built-in login view and authentication form
Source:stackexchange.com