PageRenderTime 262ms CodeModel.GetById 80ms app.highlight 4ms RepoModel.GetById 117ms app.codeStats 0ms

/tests/regressiontests/admin_widgets/widgetadmin.py

https://code.google.com/p/mango-py/
Python | 30 lines | 20 code | 7 blank | 3 comment | 1 complexity | 6321cb82b57ca4f3e0182596504f39b3 MD5 | raw file
 1"""
 2
 3"""
 4from django.contrib import admin
 5
 6import models
 7
 8class WidgetAdmin(admin.AdminSite):
 9    pass
10
11class CarAdmin(admin.ModelAdmin):
12    list_display = ['make', 'model', 'owner']
13    list_editable = ['owner']
14
15class 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
22class EventAdmin(admin.ModelAdmin):
23    raw_id_fields = ['band']
24
25site = WidgetAdmin(name='widget-admin')
26
27site.register(models.User)
28site.register(models.Car, CarAdmin)
29site.register(models.CarTire, CarTireAdmin)
30site.register(models.Event, EventAdmin)