ForeignKey or ManyToMany field search in Django Admin
Assuming you are on the VehicleInfo admin page, in your admin.py, try adding :
search_fields = ['vehicle_name' , 'vehicle_type__vehicle_type' , 'manufacturer__manufaturer' ]
Staring with the Vehicle model, vehicle_name
searches on that field.
Now manufacturer__manufacturer
will search on the manufacturer. The double underscore indicates that it is not a field on the same object
, but a foreign key
to look up, so the first manufacturer points to the manufacturer model. The second manufacturer tells it to look up the manufacturer field on that model
.