Opened 14 years ago

Closed 9 years ago

#13163 closed New feature (fixed)

Display link to change-form on inlines where model is registered in admin site

Reported by: Simon Meers Owned by: Simon Meers
Component: contrib.admin Version: dev
Severity: Normal Keywords: inline link
Cc: sree@…, cg@…, glicerinu@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

If an inline object has a get_absolute_url method, a 'View on site' link is displayed.

Here I propose that if an inline object is registered in the same admin site, an 'Edit' link is displayed in a similar fashion.

Why?

  • The inline may only display a subset of fields, so the user may wish to go to the full change form
  • 'Recursive inlines' can be accessed more easily -- e.g. Household has Person inlines, and Person has Phone inlines, etc.

The attached patch shows a draft implementation.

Questions:

  • Do we need to check if the user has change permissions on that model before displaying the link? (in the unlikely event that the user has permission to change a model which displays the inlines of a model which they do not have change permissions for). Given that I cannot see a straightforward way of checking for this without the addition of a template tag/filter, and the rarity of such setups, I'd be happy to let the user click the link and get a permission denied page.
  • Do we need an InlineModelAdmin option for enabling/disabling this link? E.g. InlineModelAdmin.show_admin_link. Or are we happy to have it enabled globally?
  • Is [ Edit ] a sufficiently understandable link label? Would "Edit in Admin", or "Display full form" or something be more appropriate?

I think the reciprocal of this would also be very useful -- ForeignKey widgets could display an [edit] link beside the "add new" (green +) link which links to the change form for the selected parent object.

Attachments (5)

admin_url.diff (8.2 KB) - added by Simon Meers 14 years ago.
InlineAdminForm changes, stacked/tabular template updates and regression tests
combined_13163_13165.diff (24.0 KB) - added by Simon Meers 13 years ago.
Combined patch for #113163 and #13165
combined_13165_13165.diff (24.0 KB) - added by Simon Meers 13 years ago.
Added unicode fix
inline_edit_link.diff (2.1 KB) - added by Dominique PERETTI 12 years ago.
Add show_edit_link = True to your ObjectInline and you get an edit link
inline_edit_link-2.diff (2.0 KB) - added by smcoll 11 years ago.
modifed version edit_inline_link.diff that supports inlined models from other apps

Download all attachments as: .zip

Change History (27)

Changed 14 years ago by Simon Meers

Attachment: admin_url.diff added

InlineAdminForm changes, stacked/tabular template updates and regression tests

comment:1 Changed 14 years ago by Karen Tracey

milestone: 1.2

This is a feature request and thus not appropriate for the 1.2 milestone at this point.

comment:2 Changed 14 years ago by Russell Keith-Magee

Component: django.contrib.adminUser Experience
Owner: nobody deleted
Triage Stage: UnreviewedAccepted

Sounds like a reasonable idea; reassigning to UX because it reflects on the UX of the admin, not admin code itself.

comment:3 Changed 14 years ago by Simon Meers

Owner: set to Simon Meers
Status: newassigned

Changed 13 years ago by Simon Meers

Attachment: combined_13163_13165.diff added

Combined patch for #113163 and #13165

comment:4 Changed 13 years ago by Simon Meers

milestone: 1.3

Changed 13 years ago by Simon Meers

Attachment: combined_13165_13165.diff added

Added unicode fix

comment:5 Changed 13 years ago by anonymous

Cc: sree@… added

comment:6 Changed 13 years ago by Christopher Grebs

Cc: cg@… added

comment:7 Changed 12 years ago by Luke Plant

Type: New feature

comment:8 Changed 12 years ago by Luke Plant

Severity: Normal

comment:9 Changed 12 years ago by anonymous

Easy pickings: unset

With Django 1.3 does not work. Is there anything like that under 1.3 ?

comment:10 Changed 12 years ago by patchhammer

Patch needs improvement: set

combined_13165_13165.diff fails to apply cleanly on to trunk

comment:11 Changed 12 years ago by Julien Phalip

UI/UX: set

comment:12 Changed 12 years ago by Julien Phalip

Component: User Experiencecontrib.admin

Changed 12 years ago by Dominique PERETTI

Attachment: inline_edit_link.diff added

Add show_edit_link = True to your ObjectInline and you get an edit link

comment:13 Changed 12 years ago by Dominique PERETTI

Needs tests: set

Hey guys, I've just added above my own implementation of this feature. Very simple, just 3 lines of code but does the job.
(This patch does it only in tabular.html).

class BooksInline(admin.TabularInline):
	model = Book
	show_edit_link = True

comment:14 Changed 12 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

comment:15 Changed 12 years ago by anonymous

any chance this will make it into 1.4 ?

comment:16 Changed 12 years ago by anonymous

still waiting for this to become a feature.

comment:17 Changed 12 years ago by glicerinu@…

Cc: glicerinu@… added

comment:18 Changed 11 years ago by Simon Charette

I packaged a simple app providing admin mixins to add a the edition and deletion links on all amin FK widgets, including those in inlines. You can find the project on github and on pypi.

Changed 11 years ago by smcoll

Attachment: inline_edit_link-2.diff added

modifed version edit_inline_link.diff that supports inlined models from other apps

comment:19 Changed 9 years ago by Daniel Hahler

@smcoll:

It looks like there is a wrong if in your patch: {% if inline_admin_form.original %}. It should check for the new show_edit_link option probably.

I assume that it won't work for many2many inlines, where you have model = Foo.bars.through?

comment:20 Changed 9 years ago by Nick Sandford

Needs documentation: set
Needs tests: unset
Patch needs improvement: unset

PR here: https://github.com/django/django/pull/2957.

I added a method AdminSite.is_registered() which takes a Model class or lowercased model name. This is needed for checking if the InlineModelAdmin's model is also registered as a ModelAdmin on the site. There is precedence for this sort of check with registries -- the app registry has apps.is_installed(), and it seems to be a reasonable method to have on the AdminSite.

Renamed the show_edit_link to show_change_link for consistency across the admin. The link will only be displayed if show_change_link = True on the inline, the model itself is also registered, and there is an inline object to change.

comment:21 Changed 9 years ago by Nick Sandford

Needs documentation: unset

Added docs, updated PR.

comment:22 Changed 9 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 9d9f0acd7e245c9f9c30727a003666618754c924:

Fixed #13163 -- Added ability to show change links on inline objects in admin.

Thanks DrMeers for the suggestion.

Note: See TracTickets for help on using tickets.
Back to Top