annotate gigs/admin.py @ 139:c962f58c2693

Support photologue photo detail views to prevent 404s in the admin.
author Brian Neal <bgneal@gmail.com>
date Sat, 08 Mar 2014 13:19:10 -0600
parents 6c7dd8bda890
children
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@128 19 def get_queryset(self, request):
bgneal@128 20 qs = super(CityAdmin, self).get_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@128 33 def get_queryset(self, request):
bgneal@128 34 qs = super(VenueAdmin, self).get_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@128 47 def get_queryset(self, request):
bgneal@128 48 qs = super(GigAdmin, self).get_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)