Django管理内联和崩溃字段

时间:2011-11-17 15:18:45

标签: django django-admin inline collapse

我使用内联来允许在admin中编辑来自Family的Drivers和Riders对象,如下所示。我希望将Driver和Rider对象折叠,但似乎只适用于类中的字段,而不是来自内联的字段。有没有办法折叠下面列出的Rider和Driver?

谢谢!

class LegAdmin(admin.ModelAdmin):
    list_display = ('drive_date', 'start_time', 'endpoint')

class DriverInline(admin.StackedInline):
    model = Driver
    extra = 0

class RiderInline(admin.StackedInline):
    model = Rider
    extra = 0

class FamilyAdmin(admin.ModelAdmin):
    inlines = [DriverInline, RiderInline]



#admin.site.register(Driver)
#admin.site.register(Member)
#admin.site.register(Rider)
admin.site.register(Leg, LegAdmin)
# admin.site.register(DriveDay)
admin.site.register(Carpool)
admin.site.register(Family, FamilyAdmin)
admin.site.register(DrivingPreference)

1 个答案:

答案 0 :(得分:0)

您可以使用javascript轻松完成此操作,只需将其加载到模型中:

示例

class Media:
   js = ('/media/admin/custom/js/inlinecollapsed.js',)