Code

Opened 3 years ago

Last modified 11 months ago

#15859 new New feature

Allow more precise placement of admin inlines

Reported by: Jeff Blaine <jblaine@…> Owned by:
Component: contrib.admin Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

I just had to copy django/contrib/admin/templates/admin/change_form.html (bad!) for wholesale replacement in my site for an easily fixable reason: I wanted my TabularInline to show at the top of the change form for my model, not at the bottom.

Inlines are for composition of a form, they're not a second-class citizen like "related objects". As such, I believe there should be a way to allow someone to at least choose top or bottom.

Attachments (0)

Change History (7)

comment:1 Changed 3 years ago by Jeff Blaine <jblaine@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.2 to 1.3

comment:2 Changed 3 years ago by julien

  • Summary changed from Allow placement of admin inline models to Allow more precise placement of admin inlines
  • Triage Stage changed from Unreviewed to Accepted

I agree. It would be even better if one could insert inlines between fieldsets.

comment:3 Changed 3 years ago by jblaine

  • Easy pickings unset

For the top/bottom case (not arbitrary placement), there appears to be a pretty simple solution from my digging around.

Add a 'position' class variable to InlineModelAdmin (just like 'extra'). From there, it's a matter of tweaking the template(s) to have a top and bottom loop over the standard inline_admin_formsets, but include a conditional that checks for 'top' (or whatever) in the top loop, and 'bottom' in the bottom loop.

If that's not feasible, it's less simple, but not a total nightmare. I think add_view() and change_view() would need to be tweaked in contrib/admin/options.py to build both top_inline_admin_formsets and bottom_inline_admin_formsets (with corresponding template tweaks).

Just offering what I dug up. Don't assume I have any real clue.

EDIT: No idea why my update above unset "Easy pickings". I didn't do it!

Last edited 3 years ago by jblaine (previous) (diff)

comment:4 Changed 3 years ago by julien

  • UI/UX set

comment:5 Changed 17 months ago by Hodson

  • Owner changed from nobody to Hodson
  • Status changed from new to assigned

comment:6 Changed 17 months ago by Hodson

  • Has patch set
  • Needs tests set
  • Owner Hodson deleted
  • Status changed from assigned to new

Here is some work I did on making this possible: https://github.com/django/django/pull/793

When defining your Admin Inline in admin.py you simply set "display_at_top = True" and this will now cause the inline to display at the top of the page.

If you do not define "display_at_top" it just defaults to displaying at the bottom.

comment:7 Changed 11 months ago by timo

  • Needs documentation set

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from (none) to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.