解决方法
您可以覆盖ModelAdmin的get_fieldsets方法.
默认实现如下所示:
def get_fieldsets(self,request,obj=None): "Hook for specifying fieldsets for the add form." if self.declared_fieldsets: return self.declared_fieldsets form = self.get_form(request,obj) fields = form.base_fields.keys() + list(self.get_readonly_fields(request,obj)) return [(None,{'fields': fields})]
所以你可以覆盖它,例如:
class MyCustomAdmin(ModelAdmin): def get_fieldsets(self,obj=None): fs = super(MyCustomAdmin,self).get_fieldsets(request,obj) # fs now contains [(None,{'fields': fields})],do with it whatever you want all_fields = fs[0][1]['fields'] return fs