2009-01-16 23:32:31 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
"""
|
|
|
|
from django.contrib import admin
|
|
|
|
|
|
|
|
import models
|
|
|
|
|
|
|
|
class WidgetAdmin(admin.AdminSite):
|
|
|
|
pass
|
|
|
|
|
2009-03-31 07:16:34 +08:00
|
|
|
class CarAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ['make', 'model', 'owner']
|
|
|
|
list_editable = ['owner']
|
2009-01-16 23:32:31 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2009-07-17 00:16:13 +08:00
|
|
|
site = WidgetAdmin(name='widget-admin')
|
2009-01-16 23:32:31 +08:00
|
|
|
|
2009-03-31 07:16:34 +08:00
|
|
|
site.register(models.User)
|
|
|
|
site.register(models.Car, CarAdmin)
|
2009-01-16 23:32:31 +08:00
|
|
|
site.register(models.CarTire, CarTireAdmin)
|