is there a nice way to add custom items to a subclassed ModelAdmin fieldset, ie have it keep all the defaults and just some extras.
(i know i could add all the defaults back myself, but was hoping for a nicer way)
You can override get_fieldsets method of ModelAdmin.
The default implementation looks like this:
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})]
So you can override it for example like this:
class MyCustomAdmin(ModelAdmin):
def get_fieldsets(self, request, 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With