bgneal@44: """ bgneal@44: Automatic admin definitions for the gigs application. bgneal@44: bgneal@44: """ bgneal@44: from django.contrib import admin bgneal@44: bgneal@44: from gigs.models import Band, City, Country, Gig, State, Venue bgneal@44: bgneal@44: bgneal@44: class CityInline(admin.TabularInline): bgneal@44: model = City bgneal@44: bgneal@44: bgneal@44: class CityAdmin(admin.ModelAdmin): bgneal@44: list_display = ['name', 'state', 'country'] bgneal@44: list_filter = ['state'] bgneal@44: search_fields = ['name'] bgneal@44: bgneal@44: def queryset(self, request): bgneal@44: qs = super(CityAdmin, self).queryset(request) bgneal@44: return qs.select_related('state', 'country') bgneal@44: bgneal@44: bgneal@44: class StateAdmin(admin.ModelAdmin): bgneal@44: inlines = [CityInline] bgneal@44: bgneal@44: bgneal@44: class VenueAdmin(admin.ModelAdmin): bgneal@44: list_filter = ['city__name'] bgneal@44: list_display = ['name', 'city'] bgneal@44: search_fields = ['name'] bgneal@44: bgneal@44: def queryset(self, request): bgneal@44: qs = super(VenueAdmin, self).queryset(request) bgneal@44: return qs.select_related('city', 'city__state', 'city__country') bgneal@44: bgneal@44: bgneal@44: class BandAdmin(admin.ModelAdmin): bgneal@44: search_fields = ['name'] bgneal@44: bgneal@44: bgneal@44: class GigAdmin(admin.ModelAdmin): bgneal@44: list_filter = ['date'] bgneal@44: save_on_top = True bgneal@44: filter_horizontal = ['bands'] bgneal@44: bgneal@44: def queryset(self, request): bgneal@44: qs = super(GigAdmin, self).queryset(request) bgneal@44: return qs.select_related('venue') bgneal@44: bgneal@44: bgneal@44: admin.site.register(Band, BandAdmin) bgneal@44: admin.site.register(City, CityAdmin) bgneal@44: admin.site.register(Country) bgneal@44: admin.site.register(Gig, GigAdmin) bgneal@44: admin.site.register(State, StateAdmin) bgneal@44: admin.site.register(Venue, VenueAdmin)