from django.contrib import admin
from .models import City, County, Affairs, Broker

# Register your models here.

@admin.register(City)
class CityAdmin(admin.ModelAdmin):
    list_display = ['name', 'slug']
    search_fields = ['name']
    readonly_fields = ['deleted_at']
    prepopulated_fields = {'slug': ('name',)}

@admin.register(County)
class CountyAdmin(admin.ModelAdmin):
    list_display = ['name', 'city', 'slug']
    list_filter = ['city']
    search_fields = ['name', 'city__name']
    readonly_fields = ['deleted_at']
    prepopulated_fields = {'slug': ('name',)}

@admin.register(Affairs)
class AffairsAdmin(admin.ModelAdmin):
    list_display = ['name', 'county', 'slug']
    list_filter = ['county__city', 'county']
    search_fields = ['name', 'county__name', 'county__city__name']
    readonly_fields = ['deleted_at']
    prepopulated_fields = {'slug': ('name',)}

@admin.register(Broker)
class BrokerAdmin(admin.ModelAdmin):
    list_display = ['name', 'affairs', 'slug']
    list_filter = ['affairs__county__city', 'affairs__county', 'affairs' ]
    search_fields = ['name', 'affairs__name', 'affairs__county__name']
    readonly_fields = ['deleted_at']
    prepopulated_fields = {'slug': ('name',)}
