I was wondering if it's possible to add a css class to the Django admin form?
For example:
@admin.register(SomeFunction)
class SomeFunctionAdmin(SortableAdmin):
fieldsets = (
(None, {
'fields': ('item1', 'item2', 'item3'),
}),
)
def get_form(self, request, obj=None, **kwargs):
form = super(SomeFunctionAdmin, self).get_form(request, obj, **kwargs)
return form
class Media:
js = (
'custom.js',
)
Now I want to add a css class to SomeFunctionAdmin, let's say I want to add .custom-form-admin class. And in my custom.js file I have some functions which search for this custom css class.
How do I add the custom css class programatically to SomeFunctionAdmin?
I imagne the code would look something like this:
@admin.register(SomeFunction)
class SomeFunctionAdmin(SortableAdmin):
fieldsets = (
(None, {
'fields': ('item1', 'item2', 'item3'),
}),
)
def get_form(self, request, obj=None, **kwargs):
form = super(SomeFunctionAdmin, self).get_form(request, obj, **kwargs)
form.set_css += 'custom-form-admin'
return form
class Media:
js = (
'custom.js',
)