view gigs/admin.py @ 130:3062c547bb90

For Django 1.6: new test discovery plus reverse now does urlquote(). My base64 keys were padded with '=' and these got quoted when doing a reverse to generate the URL. So changed the test to look for a quoted version of the key. This will change the URLs sent to users, but I believe it will all be taken care of by Django.
author Brian Neal <bgneal@gmail.com>
date Tue, 24 Dec 2013 16:47:27 -0600
parents 6c7dd8bda890
children
line wrap: on
line source
"""
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 get_queryset(self, request):
        qs = super(CityAdmin, self).get_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 get_queryset(self, request):
        qs = super(VenueAdmin, self).get_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 get_queryset(self, request):
        qs = super(GigAdmin, self).get_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)