comparison 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
comparison
equal deleted inserted replaced
70:f26cdda0ad8b 71:e2868ad47a1e
1 """
2 Automatic admin definitions for the gigs application.
3
4 """
5 from django.contrib import admin
6
7 from gigs.models import Band, City, Country, Gig, State, Venue
8
9
10 class CityInline(admin.TabularInline):
11 model = City
12
13
14 class CityAdmin(admin.ModelAdmin):
15 list_display = ['name', 'state', 'country']
16 list_filter = ['state']
17 search_fields = ['name']
18
19 def queryset(self, request):
20 qs = super(CityAdmin, self).queryset(request)
21 return qs.select_related('state', 'country')
22
23
24 class StateAdmin(admin.ModelAdmin):
25 inlines = [CityInline]
26
27
28 class VenueAdmin(admin.ModelAdmin):
29 list_filter = ['city__name']
30 list_display = ['name', 'city']
31 search_fields = ['name']
32
33 def queryset(self, request):
34 qs = super(VenueAdmin, self).queryset(request)
35 return qs.select_related('city', 'city__state', 'city__country')
36
37
38 class BandAdmin(admin.ModelAdmin):
39 search_fields = ['name']
40
41
42 class GigAdmin(admin.ModelAdmin):
43 list_filter = ['date']
44 save_on_top = True
45 filter_horizontal = ['bands']
46
47 def queryset(self, request):
48 qs = super(GigAdmin, self).queryset(request)
49 return qs.select_related('venue')
50
51
52 admin.site.register(Band, BandAdmin)
53 admin.site.register(City, CityAdmin)
54 admin.site.register(Country)
55 admin.site.register(Gig, GigAdmin)
56 admin.site.register(State, StateAdmin)
57 admin.site.register(Venue, VenueAdmin)