Source

django / tests / regressiontests / admin_widgets / widgetadmin.py

The default branch has multiple heads

"""

"""
from django.contrib import admin

import models

class WidgetAdmin(admin.AdminSite):
    pass

class CarAdmin(admin.ModelAdmin):
    list_display = ['make', 'model', 'owner']
    list_editable = ['owner']

class CarTireAdmin(admin.ModelAdmin):
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if db_field.name == "car":
            kwargs["queryset"] = models.Car.objects.filter(owner=request.user)
            return db_field.formfield(**kwargs)
        return super(CarTireAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)

class EventAdmin(admin.ModelAdmin):
    raw_id_fields = ['band']


class AlbumAdmin(admin.ModelAdmin):
    autocomplete_fields = {
        'band': { 'fields': ('name',) },
        'covered_band': { 'fields': ('name',) }
            }
    list_display = ('name', 'band', 'covered_band',)
    list_editable = ('name', 'band', 'covered_band',)

class BandAdmin(admin.ModelAdmin):
    autocomplete_fields = {
        'members': { 'fields': ('name',) },
        'roadies': { 'fields': ('name',) }
            }
    list_display = ('name', 'members', 'roadies',)
    list_editable = ('name', 'members', 'roadies',)

class MemberAdmin(admin.ModelAdmin):
    autocomplete_fields = {
        'user': { 
            'fields': ('^email', '^username', '^first_name', ),
            'id': 'email',  # weird id for test_different_id
            }
        }


site = WidgetAdmin(name='widget-admin')

site.register(models.User)
site.register(models.Album, AlbumAdmin)
site.register(models.Band, BandAdmin)
site.register(models.Car, CarAdmin)
site.register(models.CarTire, CarTireAdmin)
site.register(models.Event, EventAdmin)
site.register(models.Member, MemberAdmin)