Reputation: 297
I'm new to django and I'm trying to figure out how to create custom actions inside admin site. Let's say I want to create some sort of custom form with fancy ajax based ui. What I would normally do in .NET/PHP/Ruby is prepare some js code and a service that will be called via ajax and return json or even html. A more concrete example could be an auto complete box to manage a many to one relationship. What should I do to build such a system inside the django admin site? (I know there are a couple of ready to use solution for this. But I'm not interested: just for study purposes).
Upvotes: 1
Views: 1183
Reputation: 77251
In this particular case (a fancier widget), ModelAdmin has several useful hooks like ModelAdmin.form and ModelAdmin.formfield_overrides.
Creating a custom Django Form Widget is more elegant, but if the widget is pure JS (like many jQuery widgets), most of the time it is not worth - just override the change_form.html admin template for the Model in question.
Upvotes: 2
Reputation: 18972
You can easily change the form and the template of the ModelAdmin
.
So you're free to inject any CSS and JS you like. Take look at this presentation to get the basic idea.
Upvotes: 1