annotate gigs/admin.py @ 74:49f704e58400

Update fabfile for Django 1.4 changes.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Jul 2012 13:55:25 -0500
parents e2868ad47a1e
children 6c7dd8bda890
rev   line source
bgneal@44 1 """
bgneal@44 2 Automatic admin definitions for the gigs application.
bgneal@44 3
bgneal@44 4 """
bgneal@44 5 from django.contrib import admin
bgneal@44 6
bgneal@44 7 from gigs.models import Band, City, Country, Gig, State, Venue
bgneal@44 8
bgneal@44 9
bgneal@44 10 class CityInline(admin.TabularInline):
bgneal@44 11 model = City
bgneal@44 12
bgneal@44 13
bgneal@44 14 class CityAdmin(admin.ModelAdmin):
bgneal@44 15 list_display = ['name', 'state', 'country']
bgneal@44 16 list_filter = ['state']
bgneal@44 17 search_fields = ['name']
bgneal@44 18
bgneal@44 19 def queryset(self, request):
bgneal@44 20 qs = super(CityAdmin, self).queryset(request)
bgneal@44 21 return qs.select_related('state', 'country')
bgneal@44 22
bgneal@44 23
bgneal@44 24 class StateAdmin(admin.ModelAdmin):
bgneal@44 25 inlines = [CityInline]
bgneal@44 26
bgneal@44 27
bgneal@44 28 class VenueAdmin(admin.ModelAdmin):
bgneal@44 29 list_filter = ['city__name']
bgneal@44 30 list_display = ['name', 'city']
bgneal@44 31 search_fields = ['name']
bgneal@44 32
bgneal@44 33 def queryset(self, request):
bgneal@44 34 qs = super(VenueAdmin, self).queryset(request)
bgneal@44 35 return qs.select_related('city', 'city__state', 'city__country')
bgneal@44 36
bgneal@44 37
bgneal@44 38 class BandAdmin(admin.ModelAdmin):
bgneal@44 39 search_fields = ['name']
bgneal@44 40
bgneal@44 41
bgneal@44 42 class GigAdmin(admin.ModelAdmin):
bgneal@44 43 list_filter = ['date']
bgneal@44 44 save_on_top = True
bgneal@44 45 filter_horizontal = ['bands']
bgneal@44 46
bgneal@44 47 def queryset(self, request):
bgneal@44 48 qs = super(GigAdmin, self).queryset(request)
bgneal@44 49 return qs.select_related('venue')
bgneal@44 50
bgneal@44 51
bgneal@44 52 admin.site.register(Band, BandAdmin)
bgneal@44 53 admin.site.register(City, CityAdmin)
bgneal@44 54 admin.site.register(Country)
bgneal@44 55 admin.site.register(Gig, GigAdmin)
bgneal@44 56 admin.site.register(State, StateAdmin)
bgneal@44 57 admin.site.register(Venue, VenueAdmin)