[Django]-Should I modify/extend the admin interface, or write my own CRUD views/templates?

4👍

For our intranet, we use ModelAdmin subclasses (not mounted on the admin site via admin.site.register) for most of our C(R)UD views. By using custom templates for the views, it doesn’t look like Django admin at all. What is very convenient though, is that it already handles all the validation/saving for us.

In general, I found admin-“hacking” quite useful to quickly write up C(R)UD views and usually with relatively small changes to your ModelAdmin subclass, you can make it work for your use case.

So I’d vote for use ModelAdmin, but not the one you use in admin, hook a different template and come up with some fancy CSS.

👤ojii

1👍

I successfully created a software on top of admin.
The admin hooks (these days) allow very fine-grained customizations, i.e. in general you only need to touch what you want to change.

The changes can go from a trivial cosmetic adjustment to a complete swap-out:

If you provide templates/admin/base.html your admin site can look any way you like. And of course, a navigation bar at the top could include links to some of your own views. Watch out not to hardcode URLs in your links, always reverse.

You can overload ModelAdmin’s “change_view”, “changelist_view” etc. and swap them for your own views. For example I replaced a default changelist and its simple filtering with a search interface that allows dynamic queries to be built, result columns to be customized by the user, and loading/saving of these searches. That didn’t affect any of the other views of that ModelAdmin.

Overloading a ModelAdmin’s “get_urls()” let’s you rewrap existing admin urls to go to your own views. I did the latter for one model where I wanted the simple Add screen to be replaced by a totally customized Wizard (only leaning on ModelForm).

Don’t forget the simplest approach, esp. regarding your “AJAXy goodness”: Just define “css” and “js” in your ModelAdmin’s Meta. Want to move an inline from the bottom to sit between third and fourth field, and that’s not possible via parameters? A one-liner in jquery.

Check out “django-grappelli” for an example of how to improve admin look and feel.

What did you mean by “and of course there’s no conception of permissions or anything”?

Leave a comment