parts/django/tests/regressiontests/admin_widgets/widgetadmin.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 """
       
     2 
       
     3 """
       
     4 from django.contrib import admin
       
     5 
       
     6 import models
       
     7 
       
     8 class WidgetAdmin(admin.AdminSite):
       
     9     pass
       
    10 
       
    11 class CarAdmin(admin.ModelAdmin):
       
    12     list_display = ['make', 'model', 'owner']
       
    13     list_editable = ['owner']
       
    14 
       
    15 class CarTireAdmin(admin.ModelAdmin):
       
    16     def formfield_for_foreignkey(self, db_field, request, **kwargs):
       
    17         if db_field.name == "car":
       
    18             kwargs["queryset"] = models.Car.objects.filter(owner=request.user)
       
    19             return db_field.formfield(**kwargs)
       
    20         return super(CarTireAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
       
    21 
       
    22 class EventAdmin(admin.ModelAdmin):
       
    23     raw_id_fields = ['band']
       
    24 
       
    25 site = WidgetAdmin(name='widget-admin')
       
    26 
       
    27 site.register(models.User)
       
    28 site.register(models.Car, CarAdmin)
       
    29 site.register(models.CarTire, CarTireAdmin)
       
    30 site.register(models.Event, EventAdmin)