Ran Moshe
Ran Moshe

Reputation: 350

django admin interface - how do I collapse/expand object details in the change list view?

I would like to be able to collapse and expand object details when showing objects in the django admin change list view. For example, for an order, I would like the order list to first appear as:
+ id: 1, name: John Smith
+ id: 2, name: Jane Doe

And then when the user expands one order:
- id: 1, name: John Smith
address: 321 Oaktree Drive, LA, CA
+ id: 2, name: Jane Doe

inline objects won't work, because the order does not have a foreign key to itself. If anyone could point me in the right direction, it would be greatly appreciated.

Upvotes: 2

Views: 1198

Answers (1)

Cat Plus Plus
Cat Plus Plus

Reputation: 129964

You can override/extend both the template (ModelAdmin.change_list_template) and the view (ModelAdmin.changelist_view). The original view accepts extra_context, so you can easily add whatever you need. See contrib.admin documentation for more details.

Upvotes: 1

Related Questions