diff gigs/admin.py @ 71:e2868ad47a1e

For Django 1.4, using the new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Apr 2012 16:40:29 -0500
parents madeira/gigs/admin.py@42a6bde9913c
children 6c7dd8bda890
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gigs/admin.py	Sat Apr 14 16:40:29 2012 -0500
@@ -0,0 +1,57 @@
+"""
+Automatic admin definitions for the gigs application.
+
+"""
+from django.contrib import admin
+
+from gigs.models import Band, City, Country, Gig, State, Venue
+
+
+class CityInline(admin.TabularInline):
+    model = City
+
+
+class CityAdmin(admin.ModelAdmin):
+    list_display = ['name', 'state', 'country']
+    list_filter = ['state']
+    search_fields = ['name']
+
+    def queryset(self, request):
+        qs = super(CityAdmin, self).queryset(request)
+        return qs.select_related('state', 'country')
+
+
+class StateAdmin(admin.ModelAdmin):
+    inlines = [CityInline]
+
+
+class VenueAdmin(admin.ModelAdmin):
+    list_filter = ['city__name']
+    list_display = ['name', 'city']
+    search_fields = ['name']
+
+    def queryset(self, request):
+        qs = super(VenueAdmin, self).queryset(request)
+        return qs.select_related('city', 'city__state', 'city__country')
+
+
+class BandAdmin(admin.ModelAdmin):
+    search_fields = ['name']
+
+
+class GigAdmin(admin.ModelAdmin):
+    list_filter = ['date']
+    save_on_top = True
+    filter_horizontal = ['bands']
+
+    def queryset(self, request):
+        qs = super(GigAdmin, self).queryset(request)
+        return qs.select_related('venue')
+
+
+admin.site.register(Band, BandAdmin)
+admin.site.register(City, CityAdmin)
+admin.site.register(Country)
+admin.site.register(Gig, GigAdmin)
+admin.site.register(State, StateAdmin)
+admin.site.register(Venue, VenueAdmin)