from django.contrib import admin
from .models import *


class SchoolBuildingPhotoInline(admin.TabularInline):
    model = SchoolBuildingPhoto


@admin.register(SchoolBuilding)
class SchoolBuildingAdmin(admin.ModelAdmin):
    fields = ('school', 'building', 'begin_year', 'end_year')
    readonly_fields = fields
    list_display = ('__str__', 'has_photo')
    list_filter = ('photos',)
    inlines = [SchoolBuildingPhotoInline]

from django.contrib import admin
from .models import *


class SchoolBuildingPhotoInline(admin.TabularInline):
    model = SchoolBuildingPhoto


@admin.register(SchoolBuilding)
class SchoolBuildingAdmin(admin.ModelAdmin):
    fields = ('school', 'building', 'begin_year', 'end_year')
    readonly_fields = fields
    search_fields = ['school__names__types__value']
    list_display = ('__str__', 'has_photo')
    list_filter = ('photos',)
    inlines = [SchoolBuildingPhotoInline]

Add search based on school name
Add search based on school name

  from django.contrib import admin
  from .models import *
  
  
  class SchoolBuildingPhotoInline(admin.TabularInline):
      model = SchoolBuildingPhoto
  
  
  @admin.register(SchoolBuilding)
  class SchoolBuildingAdmin(admin.ModelAdmin):
      fields = ('school', 'building', 'begin_year', 'end_year')
      readonly_fields = fields
+     search_fields = ['school__names__types__value']
      list_display = ('__str__', 'has_photo')
      list_filter = ('photos',)
      inlines = [SchoolBuildingPhotoInline]
  
Add search based on school name
## Code Before:
from django.contrib import admin
from .models import *


class SchoolBuildingPhotoInline(admin.TabularInline):
    model = SchoolBuildingPhoto


@admin.register(SchoolBuilding)
class SchoolBuildingAdmin(admin.ModelAdmin):
    fields = ('school', 'building', 'begin_year', 'end_year')
    readonly_fields = fields
    list_display = ('__str__', 'has_photo')
    list_filter = ('photos',)
    inlines = [SchoolBuildingPhotoInline]

## Instruction:
Add search based on school name
## Code After:
from django.contrib import admin
from .models import *


class SchoolBuildingPhotoInline(admin.TabularInline):
    model = SchoolBuildingPhoto


@admin.register(SchoolBuilding)
class SchoolBuildingAdmin(admin.ModelAdmin):
    fields = ('school', 'building', 'begin_year', 'end_year')
    readonly_fields = fields
    search_fields = ['school__names__types__value']
    list_display = ('__str__', 'has_photo')
    list_filter = ('photos',)
    inlines = [SchoolBuildingPhotoInline]
